Skip to content

Commit ecfc61a

Browse files
authored
Merge pull request #19 from PaddlePaddle/develop
update
2 parents 29c12a6 + 04acba7 commit ecfc61a

12 files changed

Lines changed: 186 additions & 28 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "fluid/PaddleNLP/Senta"]
88
path = fluid/PaddleNLP/Senta
99
url = https://github.com/baidu/Senta.git
10+
[submodule "fluid/PaddleNLP/LARK"]
11+
path = fluid/PaddleNLP/LARK
12+
url = https://github.com/PaddlePaddle/LARK

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ PaddlePaddle 提供了丰富的计算单元,使得用户可以采用模块化
4343
模型|简介|模型优势|参考论文
4444
--|:--:|:--:|:--:
4545
[Transformer](./fluid/PaddleNLP/neural_machine_translation/transformer/README_cn.md)|机器翻译模型|基于self-attention,计算复杂度小,并行度高,容易学习长程依赖,翻译效果更好|[Attention Is All You Need](https://arxiv.org/abs/1706.03762)
46+
[BERT](https://github.com/PaddlePaddle/LARK/tree/develop/BERT)|语义表示模型|在多个 NLP 任务上取得 SOTA 效果,支持多卡多机训练,支持混合精度训练|[BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805)
4647
[LAC](https://github.com/baidu/lac/blob/master/README.md)|联合的词法分析模型|能够整体性地完成中文分词、词性标注、专名识别任务|[Chinese Lexical Analysis with Deep Bi-GRU-CRF Network](https://arxiv.org/abs/1807.01882)
4748
[Senta](https://github.com/baidu/Senta/blob/master/README.md)|情感倾向分析模型集|百度AI开放平台中情感倾向分析模型|-
4849
[DAM](./fluid/PaddleNLP/deep_attention_matching_net)|语义匹配模型|百度自然语言处理部发表于ACL-2018的工作,用于检索式聊天机器人多轮对话中应答的选择|[Multi-Turn Response Selection for Chatbots with Deep Attention Matching Network](http://aclweb.org/anthology/P18-1103)

fluid/PaddleCV/face_detection/widerface_eval.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ def infer(args, config):
4444
shrink, max_shrink = get_shrink(image.size[1], image.size[0])
4545

4646
det0 = detect_face(image, shrink)
47-
det1 = flip_test(image, shrink)
48-
[det2, det3] = multi_scale_test(image, max_shrink)
49-
det4 = multi_scale_test_pyramid(image, max_shrink)
50-
det = np.row_stack((det0, det1, det2, det3, det4))
51-
dets = bbox_vote(det)
47+
if args.use_gpu:
48+
det1 = flip_test(image, shrink)
49+
[det2, det3] = multi_scale_test(image, max_shrink)
50+
det4 = multi_scale_test_pyramid(image, max_shrink)
51+
det = np.row_stack((det0, det1, det2, det3, det4))
52+
dets = bbox_vote(det)
53+
else:
54+
# when infer on cpu, use a simple case
55+
dets = det0
5256

5357
keep_index = np.where(dets[:, 4] >= args.confs_threshold)[0]
5458
dets = dets[keep_index, :]

fluid/PaddleCV/gan/cycle_gan/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ env CUDA_VISIBLE_DEVICES=0 python train.py
7474

7575
```
7676
env CUDA_VISIBLE_DEVICE=0 python infer.py \
77-
--init_model="models/1" --input="./data/inputA/*" \
78-
--output="./output"
77+
--init_model="checkpoints/1" --input="./data/inputA/*" \
78+
--input_style A --output="./output"
7979
```
8080

8181
训练150轮的模型预测效果如图2和图3所示:

fluid/PaddleCV/gan/cycle_gan/infer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ def infer(args):
2626
data_shape = [-1, 3, 256, 256]
2727
input = fluid.layers.data(name='input', shape=data_shape, dtype='float32')
2828
if args.input_style == "A":
29+
model_name = 'g_a'
2930
fake = build_generator_resnet_9blocks(input, name="g_A")
3031
elif args.input_style == "B":
32+
model_name = 'g_b'
3133
fake = build_generator_resnet_9blocks(input, name="g_B")
3234
else:
3335
raise "Input with style [%s] is not supported." % args.input_style
@@ -37,7 +39,7 @@ def infer(args):
3739
place = fluid.CUDAPlace(0)
3840
exe = fluid.Executor(place)
3941
exe.run(fluid.default_startup_program())
40-
fluid.io.load_persistables(exe, args.init_model)
42+
fluid.io.load_persistables(exe, args.init_model + "/" + model_name)
4143

4244
if not os.path.exists(args.output):
4345
os.makedirs(args.output)

fluid/PaddleCV/gan/cycle_gan/layers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import numpy as np
44
import os
55

6-
use_cudnn = True
6+
# cudnn is not better when batch size is 1.
7+
use_cudnn = False
78
if 'ce_mode' in os.environ:
89
use_cudnn = False
910

11+
1012
def cal_padding(img_size, stride, filter_size, dilation=1):
1113
"""Calculate padding size."""
1214
valid_filter_size = dilation * (filter_size - 1) + 1
@@ -18,6 +20,8 @@ def cal_padding(img_size, stride, filter_size, dilation=1):
1820

1921

2022
def instance_norm(input, name=None):
23+
# TODO([email protected]): Check the accuracy when using fluid.layers.layer_norm.
24+
# return fluid.layers.layer_norm(input, begin_norm_axis=2)
2125
helper = fluid.layer_helper.LayerHelper("instance_norm", **locals())
2226
dtype = helper.input_dtype()
2327
epsilon = 1e-5

fluid/PaddleCV/gan/cycle_gan/train.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from utility import add_arguments, print_arguments, ImagePool
1818
from trainer import *
1919

20-
2120
parser = argparse.ArgumentParser(description=__doc__)
2221
add_arg = functools.partial(add_arguments, argparser=parser)
2322
# yapf: disable
@@ -36,7 +35,7 @@
3635
def train(args):
3736

3837
max_images_num = data_reader.max_images_num()
39-
shuffle=True
38+
shuffle = True
4039
if args.run_ce:
4140
np.random.seed(10)
4241
fluid.default_startup_program().random_seed = 90
@@ -66,9 +65,11 @@ def train(args):
6665
exe.run(fluid.default_startup_program())
6766
A_pool = ImagePool()
6867
B_pool = ImagePool()
69-
70-
A_reader = paddle.batch(data_reader.a_reader(shuffle=shuffle), args.batch_size)()
71-
B_reader = paddle.batch(data_reader.b_reader(shuffle=shuffle), args.batch_size)()
68+
69+
A_reader = paddle.batch(
70+
data_reader.a_reader(shuffle=shuffle), args.batch_size)()
71+
B_reader = paddle.batch(
72+
data_reader.b_reader(shuffle=shuffle), args.batch_size)()
7273
if not args.run_ce:
7374
A_test_reader = data_reader.a_test_reader()
7475
B_test_reader = data_reader.b_test_reader()
@@ -119,13 +120,13 @@ def checkpoints(epoch):
119120
if not os.path.exists(out_path):
120121
os.makedirs(out_path)
121122
fluid.io.save_persistables(
122-
exe, out_path + "/g_a", main_program=g_A_trainer.program, filename="params")
123+
exe, out_path + "/g_a", main_program=g_A_trainer.program)
123124
fluid.io.save_persistables(
124-
exe, out_path + "/g_b", main_program=g_B_trainer.program, filename="params")
125+
exe, out_path + "/g_b", main_program=g_B_trainer.program)
125126
fluid.io.save_persistables(
126-
exe, out_path + "/d_a", main_program=d_A_trainer.program, filename="params")
127+
exe, out_path + "/d_a", main_program=d_A_trainer.program)
127128
fluid.io.save_persistables(
128-
exe, out_path + "/d_b", main_program=d_B_trainer.program, filename="params")
129+
exe, out_path + "/d_b", main_program=d_B_trainer.program)
129130
print("saved checkpoint to {}".format(out_path))
130131
sys.stdout.flush()
131132

@@ -144,8 +145,21 @@ def init_model():
144145

145146
if args.init_model:
146147
init_model()
147-
losses=[[], []]
148+
losses = [[], []]
148149
t_time = 0
150+
151+
g_A_trainer_program = fluid.CompiledProgram(
152+
g_A_trainer.program).with_data_parallel(
153+
loss_name=g_A_trainer.g_loss_A.name)
154+
g_B_trainer_program = fluid.CompiledProgram(
155+
g_B_trainer.program).with_data_parallel(
156+
loss_name=g_B_trainer.g_loss_B.name)
157+
d_B_trainer_program = fluid.CompiledProgram(
158+
d_B_trainer.program).with_data_parallel(
159+
loss_name=d_B_trainer.d_loss_B.name)
160+
d_A_trainer_program = fluid.CompiledProgram(
161+
d_A_trainer.program).with_data_parallel(
162+
loss_name=d_A_trainer.d_loss_A.name)
149163
for epoch in range(args.epoch):
150164
batch_id = 0
151165
for i in range(max_images_num):
@@ -158,7 +172,7 @@ def init_model():
158172
s_time = time.time()
159173
# optimize the g_A network
160174
g_A_loss, fake_B_tmp = exe.run(
161-
g_A_trainer.program,
175+
g_A_trainer_program,
162176
fetch_list=[g_A_trainer.g_loss_A, g_A_trainer.fake_B],
163177
feed={"input_A": tensor_A,
164178
"input_B": tensor_B})
@@ -167,14 +181,14 @@ def init_model():
167181

168182
# optimize the d_B network
169183
d_B_loss = exe.run(
170-
d_B_trainer.program,
184+
d_B_trainer_program,
171185
fetch_list=[d_B_trainer.d_loss_B],
172186
feed={"input_B": tensor_B,
173187
"fake_pool_B": fake_pool_B})[0]
174188

175189
# optimize the g_B network
176190
g_B_loss, fake_A_tmp = exe.run(
177-
g_B_trainer.program,
191+
g_B_trainer_program,
178192
fetch_list=[g_B_trainer.g_loss_B, g_B_trainer.fake_A],
179193
feed={"input_A": tensor_A,
180194
"input_B": tensor_B})
@@ -183,16 +197,16 @@ def init_model():
183197

184198
# optimize the d_A network
185199
d_A_loss = exe.run(
186-
d_A_trainer.program,
200+
d_A_trainer_program,
187201
fetch_list=[d_A_trainer.d_loss_A],
188202
feed={"input_A": tensor_A,
189203
"fake_pool_A": fake_pool_A})[0]
190204
batch_time = time.time() - s_time
191205
t_time += batch_time
192-
print("epoch{}; batch{}; g_A_loss: {}; d_B_loss: {}; g_B_loss: {}; d_A_loss: {}; "
193-
"Batch_time_cost: {:.2f}".format(
194-
epoch, batch_id, g_A_loss[0], d_B_loss[0], g_B_loss[0],
195-
d_A_loss[0], batch_time))
206+
print(
207+
"epoch{}; batch{}; g_A_loss: {}; d_B_loss: {}; g_B_loss: {}; d_A_loss: {}; "
208+
"Batch_time_cost: {:.2f}".format(epoch, batch_id, g_A_loss[
209+
0], d_B_loss[0], g_B_loss[0], d_A_loss[0], batch_time))
196210
losses[0].append(g_A_loss[0])
197211
losses[1].append(d_A_loss[0])
198212
sys.stdout.flush()

fluid/PaddleNLP/LARK

Submodule LARK added at 8dbdf48
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
export MKL_NUM_THREADS=1
4+
export OMP_NUM_THREADS=1
5+
6+
7+
export CPU_NUM=1
8+
export NUM_THREADS=1
9+
10+
FLAGS_benchmark=true python train.py --enable_ce --train_dir train_big_data/ --vocab_text_path big_vocab_text.txt --vocab_tag_path big_vocab_tag.txt --model_dir big_model --batch_size 500 | python _ce.py
11+
12+
cudaid=${tagspace:=0} # use 0-th card as default
13+
export CUDA_VISIBLE_DEVICES=$cudaid
14+
15+
FLAGS_benchmark=true python train.py --enable_ce --use_cuda 1 --train_dir train_big_data/ --vocab_text_path big_vocab_text.txt --vocab_tag_path big_vocab_tag.txt --model_dir big_model --batch_size 500 --parallel 1 | python _ce.py
16+
17+
cudaid=${tagspace_4:=0,1,2,3} # use 0-th card as default
18+
export CUDA_VISIBLE_DEVICES=$cudaid
19+
20+
FLAGS_benchmark=true python train.py --enable_ce --use_cuda 1 --train_dir train_big_data/ --vocab_text_path big_vocab_text.txt --vocab_tag_path big_vocab_tag.txt --model_dir big_model --batch_size 500 --parallel 1 | python _ce.py

fluid/PaddleRec/tagspace/__init.py__

Whitespace-only changes.

0 commit comments

Comments
 (0)