Skip to content

Commit 19aa404

Browse files
authored
Merge pull request #30 from PaddlePaddle/develop
update
2 parents 17364eb + ad9d219 commit 19aa404

File tree

598 files changed

+80754
-55452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

598 files changed

+80754
-55452
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
[submodule "PaddleNLP/knowledge-driven-dialogue"]
1414
path = PaddleNLP/knowledge-driven-dialogue
1515
url = https://github.com/baidu/knowledge-driven-dialogue
16+
[submodule "PaddleNLP/language_representations_kit"]
17+
path = PaddleNLP/language_representations_kit
18+
url = https://github.com/PaddlePaddle/LARK
19+
[submodule "PaddleNLP/knowledge_driven_dialogue"]
20+
path = PaddleNLP/knowledge_driven_dialogue
21+
url = https://github.com/baidu/knowledge-driven-dialogue/

PaddleCV/gan/cycle_gan/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21

32
运行本目录下的程序示例需要使用PaddlePaddle develop最新版本。如果您的PaddlePaddle安装版本低于此要求,请按照[安装文档](http://www.paddlepaddle.org/docs/develop/documentation/zh/build_and_install/pip_install_cn.html)中的说明更新PaddlePaddle安装版本。
43

@@ -73,8 +72,8 @@ env CUDA_VISIBLE_DEVICES=0 python train.py
7372
执行以下命令读取多张图片进行预测:
7473

7574
```
76-
env CUDA_VISIBLE_DEVICE=0 python infer.py \
77-
--init_model="checkpoints/1" --input="./data/inputA/*" \
75+
env CUDA_VISIBLE_DEVICES=0 python infer.py \
76+
--init_model="output/checkpoints/1" --input="./data/horse2zebra/trainA/*" \
7877
--input_style A --output="./output"
7978
```
8079

@@ -89,3 +88,5 @@ env CUDA_VISIBLE_DEVICE=0 python infer.py \
8988
<img src="images/B2A.jpg" width="620" hspace='10'/> <br/>
9089
<strong>图 3</strong>
9190
</p>
91+
92+
>在本文示例中,均可通过修改`CUDA_VISIBLE_DEVICES`改变使用的显卡号。

PaddleCV/gan/cycle_gan/infer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import functools
33
import os
44
from PIL import Image
5-
from paddle.fluid import core
65
import paddle.fluid as fluid
76
import paddle
87
import numpy as np
@@ -44,15 +43,14 @@ def infer(args):
4443
if not os.path.exists(args.output):
4544
os.makedirs(args.output)
4645
for file in glob.glob(args.input):
47-
print "read %s" % file
4846
image_name = os.path.basename(file)
4947
image = Image.open(file)
5048
image = image.resize((256, 256))
5149
image = np.array(image) / 127.5 - 1
5250
if len(image.shape) != 3:
5351
continue
5452
data = image.transpose([2, 0, 1])[np.newaxis, :].astype("float32")
55-
tensor = core.LoDTensor()
53+
tensor = fluid.LoDTensor()
5654
tensor.set(data, place)
5755

5856
fake_temp = exe.run(fetch_list=[fake.name], feed={"input": tensor})

PaddleCV/gan/cycle_gan/train.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from scipy.misc import imsave
1313
import paddle.fluid as fluid
1414
import paddle.fluid.profiler as profiler
15-
from paddle.fluid import core
1615
import data_reader
1716
from utility import add_arguments, print_arguments, ImagePool
1817
from trainer import *
@@ -22,7 +21,7 @@
2221
# yapf: disable
2322
add_arg('batch_size', int, 1, "Minibatch size.")
2423
add_arg('epoch', int, 2, "The number of epoched to be trained.")
25-
add_arg('output', str, "./output_0", "The directory the model and the test result to be saved to.")
24+
add_arg('output', str, "./output", "The directory the model and the test result to be saved to.")
2625
add_arg('init_model', str, None, "The init model file of directory.")
2726
add_arg('save_checkpoints', bool, True, "Whether to save checkpoints.")
2827
add_arg('run_test', bool, True, "Whether to run test.")
@@ -82,8 +81,8 @@ def test(epoch):
8281
for data_A, data_B in zip(A_test_reader(), B_test_reader()):
8382
A_name = data_A[1]
8483
B_name = data_B[1]
85-
tensor_A = core.LoDTensor()
86-
tensor_B = core.LoDTensor()
84+
tensor_A = fluid.LoDTensor()
85+
tensor_B = fluid.LoDTensor()
8786
tensor_A.set(data_A[0], place)
8887
tensor_B.set(data_B[0], place)
8988
fake_A_temp, fake_B_temp, cyc_A_temp, cyc_B_temp = exe.run(
@@ -168,8 +167,8 @@ def init_model():
168167
for i in range(max_images_num):
169168
data_A = next(A_reader)
170169
data_B = next(B_reader)
171-
tensor_A = core.LoDTensor()
172-
tensor_B = core.LoDTensor()
170+
tensor_A = fluid.LoDTensor()
171+
tensor_B = fluid.LoDTensor()
173172
tensor_A.set(data_A, place)
174173
tensor_B.set(data_B, place)
175174
s_time = time.time()

PaddleCV/human_pose_estimation/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ This is a simple demonstration of re-implementation in [PaddlePaddle.Fluid](http
99
1010
## Requirements
1111

12-
- Python == 2.7
13-
- PaddlePaddle >= 1.1.0
12+
- Python == 2.7 or 3.6
13+
- PaddlePaddle >= 1.1.0 (<= 1.3.0)
1414
- opencv-python >= 3.3
1515

1616
## Environment
1717

18-
The code is developed and tested under 4 Tesla K40/P40 GPUS cards on CentOS with installed CUDA-9.2/8.0 and cuDNN-7.1.
18+
The code is developed and tested under 4 Tesla K40/P40 GPUS cards on CentOS with installed CUDA-9.0/8.0 and cuDNN-7.0.
1919

2020
## Results on MPII Val
2121
| Arch | Head | Shoulder | Elbow | Wrist | Hip | Knee | Ankle | Mean | [email protected]| Models |
@@ -85,19 +85,21 @@ python2 setup.py install --user
8585
Downloading the checkpoints of Pose-ResNet-50 trained on MPII dataset from [here](https://paddlemodels.bj.bcebos.com/pose/pose-resnet50-mpii-384x384.tar.gz). Extract it into the folder `checkpoints` under the directory root of this repo. Then run
8686

8787
```bash
88-
python val.py --dataset 'mpii' --checkpoint 'checkpoints/pose-resnet50-mpii-384x384'
88+
python val.py --dataset 'mpii' --checkpoint 'checkpoints/pose-resnet50-mpii-384x384' --data_root 'data/mpii'
8989
```
9090

9191
### Perform Training
9292

9393
```bash
94-
python train.py --dataset 'mpii' # or coco
94+
python train.py --dataset 'mpii' --data_root 'data/mpii'
9595
```
9696

9797
**Note**: Configurations for training are aggregated in the `lib/mpii_reader.py` and `lib/coco_reader.py`.
9898

9999
### Perform Test on Images
100100

101+
We also support to apply pre-trained models on customized images.
102+
101103
Put the images into the folder `test` under the directory root of this repo. Then run
102104

103105
```bash

PaddleCV/human_pose_estimation/README_cn.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
1010
## 环境依赖
1111

12-
本目录下的代码均在4卡Tesla K40/P40 GPU,CentOS系统,CUDA-9.2/8.0,cuDNN-7.1环境下测试运行无误
12+
本目录下的代码均在4卡Tesla K40/P40 GPU,CentOS系统,CUDA-9.0/8.0,cuDNN-7.0环境下测试运行无误
1313

14-
- Python == 2.7
15-
- PaddlePaddle >= 1.1.0
14+
- Python == 2.7 / 3.6
15+
- PaddlePaddle >= 1.1.0 (<= 1.3.0)
1616
- opencv-python >= 3.3
1717

1818
## MPII Val结果
@@ -83,19 +83,21 @@ python2 setup.py install --user
8383
下载COCO/MPII预训练模型(见上表最后一列所附链接),保存到根目录下的'checkpoints'文件夹中,运行:
8484

8585
```bash
86-
python val.py --dataset 'mpii' --checkpoint 'checkpoints/pose-resnet50-mpii-384x384'
86+
python val.py --dataset 'mpii' --checkpoint 'checkpoints/pose-resnet50-mpii-384x384' --data_root 'data/mpii'
8787
```
8888

8989
### 模型训练
9090

9191
```bash
92-
python train.py --dataset 'mpii' # or coco
92+
python train.py --dataset 'mpii'
9393
```
9494

9595
**说明** 详细参数配置已保存到`lib/mpii_reader.py``lib/coco_reader.py`文件中,通过设置dataset来选择使用具体的参数配置
9696

9797
### 模型测试(任意图片,使用上述COCO或MPII预训练好的模型)
9898

99+
同时,我们支持使用预训练好的关键点检测模型预测任意图片
100+
99101
将测试图片放入根目录下的'test'文件夹中,执行
100102

101103
```bash
@@ -104,4 +106,4 @@ python test.py --checkpoint 'checkpoints/pose-resnet-50-384x384-mpii'
104106

105107
## 引用
106108

107-
- Simple Baselines for Human Pose Estimation and Tracking in PyTorch [`code`](https://github.com/Microsoft/human-pose-estimation.pytorch#data-preparation)
109+
- Simple Baselines for Human Pose Estimation and Tracking in PyTorch [`code`](https://github.com/Microsoft/human-pose-estimation.pytorch#data-preparation)

PaddleCV/human_pose_estimation/test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
"""Functions for inference."""
1717

18-
import os
18+
import sys
1919
import argparse
2020
import functools
2121
import paddle
@@ -34,13 +34,18 @@
3434
add_arg('dataset', str, 'mpii', "Dataset")
3535
add_arg('use_gpu', bool, True, "Whether to use GPU or not.")
3636
add_arg('kp_dim', int, 16, "Class number.")
37-
add_arg('model_save_dir', str, "output", "Model save directory")
3837
add_arg('with_mem_opt', bool, True, "Whether to use memory optimization or not.")
3938
add_arg('checkpoint', str, None, "Whether to resume checkpoint.")
4039
add_arg('flip_test', bool, True, "Flip test")
4140
add_arg('shift_heatmap', bool, True, "Shift heatmap")
4241
# yapf: enable
4342

43+
44+
def print_immediately(s):
45+
print(s)
46+
sys.stdout.flush()
47+
48+
4449
def test(args):
4550
import lib.mpii_reader as reader
4651
if args.dataset == 'coco':
@@ -89,6 +94,7 @@ def test(args):
8994
fetch_list = [image.name, output.name]
9095

9196
for batch_id, data in enumerate(test_reader()):
97+
print_immediately("Processing batch #%d" % batch_id)
9298
num_images = len(data)
9399

94100
file_ids = []
@@ -124,6 +130,7 @@ def test(args):
124130
out_heatmaps = (out_heatmaps + output_flipped) * 0.5
125131
save_predict_results(input_image, out_heatmaps, file_ids, fold_name='results')
126132

133+
127134
if __name__ == '__main__':
128135
args = parser.parse_args()
129136
test(args)

PaddleCV/human_pose_estimation/train.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Functions for training."""
1717

1818
import os
19+
import sys
1920
import numpy as np
2021
import cv2
2122
import paddle
@@ -75,6 +76,12 @@ def optimizer_setting(args, params):
7576

7677
return optimizer
7778

79+
80+
def print_immediately(s):
81+
print(s)
82+
sys.stdout.flush()
83+
84+
7885
def train(args):
7986
if args.dataset == 'coco':
8087
import lib.coco_reader as reader
@@ -152,7 +159,7 @@ def if_exist(var):
152159

153160
loss = np.mean(np.array(loss))
154161

155-
print('Epoch [{:4d}/{:3d}] LR: {:.10f} '
162+
print_immediately('Epoch [{:4d}/{:3d}] LR: {:.10f} '
156163
'Loss = {:.5f}'.format(
157164
batch_id, pass_id, current_lr[0], loss))
158165

PaddleCV/human_pose_estimation/utils/coco_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import pickle
2525

2626
from utils.base_evaluator import BaseEvaluator
27+
from utils.nms_utils import oks_nms
2728
from pycocotools.coco import COCO
2829
from pycocotools.cocoeval import COCOeval
29-
from nms.nms import oks_nms
3030

3131

3232
class COCOEvaluator(BaseEvaluator):
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2019-present, Baidu, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
##############################################################################
15+
from __future__ import absolute_import
16+
from __future__ import division
17+
from __future__ import print_function
18+
19+
import numpy as np
20+
21+
22+
def oks_iou(g, d, a_g, a_d, sigmas=None, in_vis_thre=None):
23+
if not isinstance(sigmas, np.ndarray):
24+
sigmas = np.array([.26, .25, .25, .35, .35, .79, .79, .72, .72, .62, .62, 1.07, 1.07, .87, .87, .89, .89]) / 10.0
25+
vars = (sigmas * 2) ** 2
26+
xg = g[0::3]
27+
yg = g[1::3]
28+
vg = g[2::3]
29+
ious = np.zeros((d.shape[0]))
30+
for n_d in range(0, d.shape[0]):
31+
xd = d[n_d, 0::3]
32+
yd = d[n_d, 1::3]
33+
vd = d[n_d, 2::3]
34+
dx = xd - xg
35+
dy = yd - yg
36+
e = (dx ** 2 + dy ** 2) / vars / ((a_g + a_d[n_d]) / 2 + np.spacing(1)) / 2
37+
if in_vis_thre is not None:
38+
ind = list(vg > in_vis_thre) and list(vd > in_vis_thre)
39+
e = e[ind]
40+
ious[n_d] = np.sum(np.exp(-e)) / e.shape[0] if e.shape[0] != 0 else 0.0
41+
return ious
42+
43+
44+
def oks_nms(kpts_db, thresh, sigmas=None, in_vis_thre=None):
45+
"""
46+
greedily select boxes with high confidence and overlap with current maximum <= thresh
47+
rule out overlap >= thresh, overlap = oks
48+
:param kpts_db
49+
:param thresh: retain overlap < thresh
50+
:return: indexes to keep
51+
"""
52+
if len(kpts_db) == 0:
53+
return []
54+
55+
scores = np.array([kpts_db[i]['score'] for i in range(len(kpts_db))])
56+
kpts = np.array([kpts_db[i]['keypoints'].flatten() for i in range(len(kpts_db))])
57+
areas = np.array([kpts_db[i]['area'] for i in range(len(kpts_db))])
58+
59+
order = scores.argsort()[::-1]
60+
61+
keep = []
62+
while order.size > 0:
63+
i = order[0]
64+
keep.append(i)
65+
66+
oks_ovr = oks_iou(kpts[i], kpts[order[1:]], areas[i], areas[order[1:]], sigmas, in_vis_thre)
67+
68+
inds = np.where(oks_ovr <= thresh)[0]
69+
order = order[inds + 1]
70+
71+
return keep

0 commit comments

Comments
 (0)