Skip to content

Commit 586157c

Browse files
authored
[Matting] Update README and Fix Export Bug Of HumanMatting (#1730)
1 parent 2db1a09 commit 586157c

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

contrib/Matting/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ python bg_replace.py \
200200
--bg_path path/to/your/background/image \
201201
--save_dir ./output/results
202202
```
203-
If the model requires trimap information, pass the trimap path through '--trimap_path'.
203+
If the model requires trimap information, pass the trimap path through `--trimap_path`.
204204

205205
If `--bg_path` is not provided, green background is used。
206206

207+
**note:** `--image_path` must be a image path。
208+
207209
You can directly download the provided model for background replacement.
208210

209211
Run the following command to view more parameters.
@@ -231,7 +233,7 @@ python export.py --help
231233
python deploy/python/infer.py \
232234
--config output/export/deploy.yaml \
233235
--image_path data/PPM-100/val/fg/ \
234-
--save_dir ouput/results
236+
--save_dir output/results
235237
```
236238
If the model requires trimap information, pass the trimap path through '--trimap_path'.
237239

contrib/Matting/README_CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ python bg_replace.py \
208208

209209
若不提供`--bg_path`, 则采用绿色作为背景。
210210

211+
**注意:** `--image_path`必须是一张图片的具体路径。
212+
211213
你可以直接下载我们提供的模型进行背景替换。
212214

213215
更多参数信息请运行如下命令进行查看:
@@ -235,7 +237,7 @@ python export.py --help
235237
python deploy/python/infer.py \
236238
--config output/export/deploy.yaml \
237239
--image_path data/PPM-100/val/fg/ \
238-
--save_dir ouput/results
240+
--save_dir output/results
239241
```
240242
如模型需要trimap信息,需要通过`--trimap_path`传入trimap路径。
241243

contrib/Matting/configs/human_matting/human_matting_resnet34_vd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ model:
3939
type: HumanMatting
4040
backbone:
4141
type: ResNet34_vd
42-
pretrained: https://bj.bcebos.com/paddleseg/dygraph/ResNet34_vd_pretrained.pdparams
42+
pretrained: https://paddleseg.bj.bcebos.com/matting/models/ResNet34_vd_pretrained/model.pdparams
4343
pretrained: Null
4444
if_refine: True
4545

contrib/Matting/deploy/human_matting_android_demo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
English | [简体中文](README_CN.md)
22

33
# Human Matting Android Demo
4-
Based on [PaddleSeg](https://github.com/paddlepaddle/paddleseg/tree/develop)[MODNet](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/contrib/Matting) algorithm to realise human matting(Android demo).
4+
Based on [PaddleSeg](https://github.com/paddlepaddle/paddleseg/tree/develop) [MODNet](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/contrib/Matting) algorithm to realise human matting(Android demo).
55

66
You can directly download and install the example project [apk](https://paddleseg.bj.bcebos.com/matting/models/deploy/app-debug.apk) to experience。
77

contrib/Matting/deploy/human_matting_android_demo/README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*注:此安卓demo基于[Paddle-Lite](https://paddlelite.paddlepaddle.org.cn/)开发,PaddleLite版本为2.8.0。*
2727

2828
### 2.3 预测
29-
* 在人像抠图Demo中,默认会载入一张人像图像,并会在图像下方给出CPU的预测结果和预测时延
29+
* 在人像抠图Demo中,默认会载入一张人像图像,并会在图像下方给出CPU的预测结果和预测延时
3030
* 在人像抠图Demo中,你还可以通过右上角的"打开本地相册"和"打开摄像头拍照"按钮分别从相册或相机中加载测试图像然后进行预测推理;
3131

3232
*注意:demo中拍照时照片会自动压缩,想测试拍照原图效果,可使用手机相机拍照后从相册中打开进行预测。*
@@ -80,7 +80,7 @@ val_dataset:
8080
mode: val
8181
get_trimap: False
8282
```
83-
上述修改中尤其注意short_size: 256这个字段,这个值直接决定我们最终的推理图像采用的尺寸大小。这个字段值设置太小会影响预测精度,设置太大会影响手机推理速度(甚至造成手机因性能问题无法完成推理而奔溃)。经过实际测试,对于hrnet18,该字段设置为256较好。
83+
上述修改中尤其注意short_size: 256这个字段,这个值直接决定我们最终的推理图像采用的尺寸大小。这个字段值设置太小会影响预测精度,设置太大会影响手机推理速度(甚至造成手机因性能问题无法完成推理而崩溃)。经过实际测试,对于hrnet18,该字段设置为256较好。
8484
8585
完成配置文件修改后,采用下面的命令进行静态图导出:
8686
``` shell

contrib/Matting/model/human_matting.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,14 @@ def __init__(self,
162162

163163
def forward(self, data):
164164
src = data['img']
165-
src_h, src_w = src.shape[2:]
165+
src_h, src_w = paddle.shape(src)[2:]
166166
if self.if_refine:
167-
if (src_h % 4 != 0) or (src_w % 4) != 0:
168-
raise ValueError(
169-
'The input image must have width and height that are divisible by 4'
170-
)
167+
# It is not need when exporting.
168+
if isinstance(src_h, paddle.Tensor):
169+
if (src_h % 4 != 0) or (src_w % 4) != 0:
170+
raise ValueError(
171+
'The input image must have width and height that are divisible by 4'
172+
)
171173

172174
# Downsample src for backbone
173175
src_sm = F.interpolate(
@@ -366,7 +368,7 @@ def forward(self, src, pha, err, hid, tri):
366368
hid: (B, 32, Hc, Hc) coarse hidden encoding.
367369
tri: (B, 1, Hc, Hc) trimap prediction.
368370
'''
369-
h_full, w_full = src.shape[2:]
371+
h_full, w_full = paddle.shape(src)[2:]
370372
h_half, w_half = h_full // 2, w_full // 2
371373
h_quat, w_quat = h_full // 4, w_full // 4
372374

0 commit comments

Comments
 (0)