Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
71ee4cf6
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
接近 2 年 前同步成功
通知
284
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
71ee4cf6
编写于
10月 14, 2022
作者:
jm_12138
提交者:
GitHub
10月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update deeplabv3p_xception65_humanseg (#2008)
* update deeplabv3p_xception65_humanseg * update save inference model
上级
00047359
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
116 addition
and
61 deletion
+116
-61
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README.md
...tic_segmentation/deeplabv3p_xception65_humanseg/README.md
+9
-15
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README_en.md
..._segmentation/deeplabv3p_xception65_humanseg/README_en.md
+9
-15
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/data_feed.py
..._segmentation/deeplabv3p_xception65_humanseg/data_feed.py
+0
-1
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/module.py
...tic_segmentation/deeplabv3p_xception65_humanseg/module.py
+12
-29
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/processor.py
..._segmentation/deeplabv3p_xception65_humanseg/processor.py
+0
-1
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/test.py
...antic_segmentation/deeplabv3p_xception65_humanseg/test.py
+86
-0
未找到文件。
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README.md
浏览文件 @
71ee4cf6
...
...
@@ -70,11 +70,11 @@
```python
def segmentation(images=None,
paths=None,
batch_size=1,
use_gpu=False,
visualization=False,
output_dir='humanseg_output')
paths=None,
batch_size=1,
use_gpu=False,
visualization=False,
output_dir='humanseg_output')
```
- 预测API,用于人像分割。
...
...
@@ -95,20 +95,14 @@
* data (numpy.ndarray): 人像分割结果,仅包含Alpha通道,取值为0-255 (0为全透明,255为不透明),也即取值越大的像素点越可能为人体,取值越小的像素点越可能为背景。
```python
def save_inference_model(dirname,
model_filename=None,
params_filename=None,
combined=True)
def save_inference_model(dirname)
```
- 将模型保存到指定路径。
- **参数**
* dirname: 存在模型的目录名称
* model\_filename: 模型文件名称,默认为\_\_model\_\_
* params\_filename: 参数文件名称,默认为\_\_params\_\_(仅当`combined`为True时生效)
* combined: 是否将参数保存到统一的一个文件中
* dirname: 模型保存路径
## 四、服务部署
...
...
@@ -175,10 +169,10 @@
修复预测后处理图像数据超过[0,255]范围
*
1.
1.2
*
1.
2.0
移除 fluid api
-
```shell
$ hub install deeplabv3p_xception65_humanseg==1.
1.2
$ hub install deeplabv3p_xception65_humanseg==1.
2.0
```
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/README_en.md
浏览文件 @
71ee4cf6
...
...
@@ -70,11 +70,11 @@
- ```python
def segmentation(images=None,
paths=None,
batch_size=1,
use_gpu=False,
visualization=False,
output_dir='humanseg_output')
paths=None,
batch_size=1,
use_gpu=False,
visualization=False,
output_dir='humanseg_output')
```
- Prediction API, generating segmentation result.
...
...
@@ -94,19 +94,13 @@
* data (numpy.ndarray): The result of portrait segmentation.
- ```python
def save_inference_model(dirname,
model_filename=None,
params_filename=None,
combined=True)
def save_inference_model(dirname)
```
- Save the model to the specified path.
- **Parameters**
* dirname: Save path.
* model\_filename: Model file name,defalt is \_\_model\_\_
* params\_filename: Parameter file name,defalt is \_\_params\_\_(Only takes effect when `combined` is True)
* combined: Whether to save the parameters to a unified file.
* dirname: Model save path.
## IV. Server Deployment
...
...
@@ -171,10 +165,10 @@
Fix the bug of image value out of range
*
1.
1.2
*
1.
2.0
Remove fluid api
-
```shell
$ hub install deeplabv3p_xception65_humanseg==1.
1.2
$ hub install deeplabv3p_xception65_humanseg==1.
2.0
```
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/data_feed.py
浏览文件 @
71ee4cf6
...
...
@@ -5,7 +5,6 @@ from collections import OrderedDict
import
cv2
import
numpy
as
np
from
PIL
import
Image
__all__
=
[
'reader'
]
...
...
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/module.py
浏览文件 @
71ee4cf6
...
...
@@ -8,14 +8,13 @@ import os
import
numpy
as
np
import
paddle
from
deeplabv3p_xception65_humanseg
.data_feed
import
reader
from
deeplabv3p_xception65_humanseg
.processor
import
base64_to_cv2
from
deeplabv3p_xception65_humanseg
.processor
import
cv2_to_base64
from
deeplabv3p_xception65_humanseg
.processor
import
postprocess
from
.data_feed
import
reader
from
.processor
import
base64_to_cv2
from
.processor
import
cv2_to_base64
from
.processor
import
postprocess
from
paddle.inference
import
Config
from
paddle.inference
import
create_predictor
import
paddlehub
as
hub
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.module.module
import
runnable
from
paddlehub.module.module
import
serving
...
...
@@ -26,18 +25,20 @@ from paddlehub.module.module import serving
author
=
"baidu-vis"
,
author_email
=
""
,
summary
=
"DeepLabv3+ is a semantic segmentation model."
,
version
=
"1.
1.2
"
)
class
DeeplabV3pXception65HumanSeg
(
hub
.
Module
)
:
version
=
"1.
2.0
"
)
class
DeeplabV3pXception65HumanSeg
:
def
_
initialize
(
self
):
self
.
default_pretrained_model_path
=
os
.
path
.
join
(
self
.
directory
,
"deeplabv3p_xception65_humanseg_model"
)
def
_
_init__
(
self
):
self
.
default_pretrained_model_path
=
os
.
path
.
join
(
self
.
directory
,
"deeplabv3p_xception65_humanseg_model"
,
"model"
)
self
.
_set_config
()
def
_set_config
(
self
):
"""
predictor config setting
"""
cpu_config
=
Config
(
self
.
default_pretrained_model_path
)
model
=
self
.
default_pretrained_model_path
+
'.pdmodel'
params
=
self
.
default_pretrained_model_path
+
'.pdiparams'
cpu_config
=
Config
(
model
,
params
)
cpu_config
.
disable_glog_info
()
cpu_config
.
disable_gpu
()
self
.
cpu_predictor
=
create_predictor
(
cpu_config
)
...
...
@@ -49,7 +50,7 @@ class DeeplabV3pXception65HumanSeg(hub.Module):
except
:
use_gpu
=
False
if
use_gpu
:
gpu_config
=
Config
(
self
.
default_pretrained_model_path
)
gpu_config
=
Config
(
model
,
params
)
gpu_config
.
disable_glog_info
()
gpu_config
.
enable_use_gpu
(
memory_pool_init_size_mb
=
1000
,
device_id
=
0
)
self
.
gpu_predictor
=
create_predictor
(
gpu_config
)
...
...
@@ -134,24 +135,6 @@ class DeeplabV3pXception65HumanSeg(hub.Module):
res
.
append
(
out
)
return
res
def
save_inference_model
(
self
,
dirname
,
model_filename
=
None
,
params_filename
=
None
,
combined
=
True
):
if
combined
:
model_filename
=
"__model__"
if
not
model_filename
else
model_filename
params_filename
=
"__params__"
if
not
params_filename
else
params_filename
place
=
paddle
.
CPUPlace
()
exe
=
paddle
.
Executor
(
place
)
program
,
feeded_var_names
,
target_vars
=
paddle
.
static
.
load_inference_model
(
dirname
=
self
.
default_pretrained_model_path
,
executor
=
exe
)
paddle
.
static
.
save_inference_model
(
dirname
=
dirname
,
main_program
=
program
,
executor
=
exe
,
feeded_var_names
=
feeded_var_names
,
target_vars
=
target_vars
,
model_filename
=
model_filename
,
params_filename
=
params_filename
)
@
serving
def
serving_method
(
self
,
images
,
**
kwargs
):
"""
...
...
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/processor.py
浏览文件 @
71ee4cf6
...
...
@@ -5,7 +5,6 @@ from __future__ import print_function
import
os
import
time
from
collections
import
OrderedDict
import
base64
import
cv2
...
...
modules/image/semantic_segmentation/deeplabv3p_xception65_humanseg/test.py
0 → 100644
浏览文件 @
71ee4cf6
import
os
import
shutil
import
unittest
import
cv2
import
requests
import
numpy
as
np
import
paddlehub
as
hub
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'0'
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
)
->
None
:
img_url
=
'https://unsplash.com/photos/pg_WCHWSdT8/download?ixid=MnwxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNjYyNDM2ODI4&force=true&w=640'
if
not
os
.
path
.
exists
(
'tests'
):
os
.
makedirs
(
'tests'
)
response
=
requests
.
get
(
img_url
)
assert
response
.
status_code
==
200
,
'Network Error.'
with
open
(
'tests/test.jpg'
,
'wb'
)
as
f
:
f
.
write
(
response
.
content
)
cls
.
module
=
hub
.
Module
(
name
=
"deeplabv3p_xception65_humanseg"
)
@
classmethod
def
tearDownClass
(
cls
)
->
None
:
shutil
.
rmtree
(
'tests'
)
shutil
.
rmtree
(
'inference'
)
shutil
.
rmtree
(
'humanseg_output'
)
def
test_segmentation1
(
self
):
results
=
self
.
module
.
segmentation
(
paths
=
[
'tests/test.jpg'
],
use_gpu
=
False
,
visualization
=
False
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_segmentation2
(
self
):
results
=
self
.
module
.
segmentation
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
False
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_segmentation3
(
self
):
results
=
self
.
module
.
segmentation
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
False
,
visualization
=
True
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_segmentation4
(
self
):
results
=
self
.
module
.
segmentation
(
images
=
[
cv2
.
imread
(
'tests/test.jpg'
)],
use_gpu
=
True
,
visualization
=
False
)
self
.
assertIsInstance
(
results
[
0
][
'data'
],
np
.
ndarray
)
def
test_segmentation5
(
self
):
self
.
assertRaises
(
AssertionError
,
self
.
module
.
segmentation
,
paths
=
[
'no.jpg'
]
)
def
test_segmentation6
(
self
):
self
.
assertRaises
(
AttributeError
,
self
.
module
.
segmentation
,
images
=
[
'test.jpg'
]
)
def
test_save_inference_model
(
self
):
self
.
module
.
save_inference_model
(
'./inference/model'
)
self
.
assertTrue
(
os
.
path
.
exists
(
'./inference/model.pdmodel'
))
self
.
assertTrue
(
os
.
path
.
exists
(
'./inference/model.pdiparams'
))
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录