Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
0692cc94
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0692cc94
编写于
9月 24, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add serving demo
上级
960a868a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
92 addition
and
32 deletion
+92
-32
deploy/paddle-serving/README.md
deploy/paddle-serving/README.md
+9
-32
deploy/paddle-serving/postprocess.py
deploy/paddle-serving/postprocess.py
+58
-0
deploy/paddle-serving/seg_client.py
deploy/paddle-serving/seg_client.py
+25
-0
未找到文件。
deploy/paddle-serving/README.md
浏览文件 @
0692cc94
...
...
@@ -6,7 +6,7 @@ PaddleServing是Paddle的在线预测服务框架,可以快速部署训练好
## 2.安装Paddle Serving
目前PaddleServing的正式版本为0.3.2版本
,本文中的示例需要develop版本的paddle_serving_app,请从
[
链接
](
https://github.com/PaddlePaddle/Serving/blob/develop/doc/LATEST_PACKAGES.md#app
)
中下载并安装
。
目前PaddleServing的正式版本为0.3.2版本。
服务端安装:
...
...
@@ -47,41 +47,18 @@ python pdseg/export_serving_model.py --cfg configs/unet_optic.yaml TEST.TEST_MOD
`freeze_model/serving_server`
目录下包含了模型文件和serving server端配置文件,
`freeze_model/serving_client`
目录下包含了serving client端配置文件。
分别将serving_server和serving_client复制到server和client启动的路径下。
## 4.部署预测服务
```
shell
python
-m
paddle_serving_server.serve
--model
unet_model
/
--port
9494
# CPU
python
-m
paddle_serving_server_gpu.serve
--model
unet_model
--port
9494
--gpu_ids
0
#GPU
python
-m
paddle_serving_server.serve
--model
serving_server
/
--port
9494
# CPU
python
-m
paddle_serving_server_gpu.serve
--model
serving_server
--port
9494
--gpu_ids
0
#GPU
```
## 5.执行预测
```
python
#seg_client.py
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
Sequential
,
File2Image
,
Resize
,
Transpose
,
BGR2RGB
,
SegPostprocess
,
Normalize
,
Div
import
sys
import
cv2
client
=
Client
()
client
.
load_client_config
(
"unet_client/serving_client_conf.prototxt"
)
client
.
connect
([
"127.0.0.1:9494"
])
preprocess
=
Sequential
([
File2Image
(),
Resize
(
(
512
,
512
),
interpolation
=
cv2
.
INTER_LINEAR
),
Div
(
255.0
),
Normalize
([
0.5
,
0.5
,
0.5
],
[
0.5
,
0.5
,
0.5
],
False
),
Transpose
((
2
,
0
,
1
))
])
postprocess
=
SegPostprocess
(
2
)
filename
=
"N0060.jpg"
im
=
preprocess
(
filename
)
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
},
fetch
=
[
"transpose_1.tmp_0"
])
fetch_map
[
"filename"
]
=
filename
postprocess
(
fetch_map
)
```
shell
python seg_client.py ../../dataset/optic_disc_seg/JPEGImages/N0060.jpg
```
脚本执行之后,当前目录下生成处理后的图片。
完整的部署示例请参考PaddleServing的
[
unet示例
](
https://github.com/PaddlePaddle/Serving/tree/develop/python/examples/unet_for_image_seg
)
。
脚本执行之后,会在输入图片所在的目录下生成处理后的图片
示例中为
`../../dataset/optic_disc_seg/JPEGImages/N0060_jpg_mask.png`
和
`../../dataset/optic_disc_seg/JPEGImages/N0060_jpg_result.png`
deploy/paddle-serving/postprocess.py
0 → 100644
浏览文件 @
0692cc94
import
cv2
import
numpy
as
np
def
generate_colormap
(
num_classes
):
color_map
=
num_classes
*
[
0
,
0
,
0
]
for
i
in
range
(
0
,
num_classes
):
j
=
0
lab
=
i
while
lab
:
color_map
[
i
*
3
]
|=
(((
lab
>>
0
)
&
1
)
<<
(
7
-
j
))
color_map
[
i
*
3
+
1
]
|=
(((
lab
>>
1
)
&
1
)
<<
(
7
-
j
))
color_map
[
i
*
3
+
2
]
|=
(((
lab
>>
2
)
&
1
)
<<
(
7
-
j
))
j
+=
1
lab
>>=
3
color_map
=
[
color_map
[
i
:
i
+
3
]
for
i
in
range
(
0
,
len
(
color_map
),
3
)]
return
color_map
class
SegPostprocess
(
object
):
def
__init__
(
self
,
class_num
):
self
.
class_num
=
class_num
def
__call__
(
self
,
image_with_result
):
if
"filename"
not
in
image_with_result
:
raise
(
"filename should be specified in postprocess"
)
img_name
=
image_with_result
[
"filename"
]
ori_img
=
cv2
.
imread
(
img_name
,
-
1
)
ori_shape
=
ori_img
.
shape
mask
=
None
for
key
in
image_with_result
:
if
".lod"
in
key
or
"filename"
in
key
:
continue
mask
=
image_with_result
[
key
][
0
]
if
mask
is
None
:
raise
(
"segment mask should be specified in postprocess"
)
mask
=
np
.
argmax
(
mask
,
axis
=
0
)
mask
=
mask
.
astype
(
"uint8"
)
mask_png
=
mask
score_png
=
mask_png
[:,
:,
np
.
newaxis
]
score_png
=
np
.
concatenate
([
score_png
]
*
3
,
axis
=
2
)
color_map
=
generate_colormap
(
self
.
class_num
)
for
i
in
range
(
score_png
.
shape
[
0
]):
for
j
in
range
(
score_png
.
shape
[
1
]):
score_png
[
i
,
j
]
=
color_map
[
score_png
[
i
,
j
,
0
]]
ext_pos
=
img_name
.
rfind
(
"."
)
img_name_fix
=
img_name
[:
ext_pos
]
+
"_"
+
img_name
[
ext_pos
+
1
:]
mask_save_name
=
img_name_fix
+
"_mask.png"
cv2
.
imwrite
(
mask_save_name
,
mask_png
,
[
cv2
.
CV_8UC1
])
vis_result_name
=
img_name_fix
+
"_result.png"
result_png
=
score_png
result_png
=
cv2
.
resize
(
result_png
,
(
ori_shape
[
1
],
ori_shape
[
0
]),
fx
=
0
,
fy
=
0
,
interpolation
=
cv2
.
INTER_CUBIC
)
cv2
.
imwrite
(
vis_result_name
,
result_png
,
[
cv2
.
CV_8UC1
])
deploy/paddle-serving/seg_client.py
0 → 100644
浏览文件 @
0692cc94
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
Sequential
,
File2Image
,
Resize
,
Transpose
,
BGR2RGB
,
Normalize
,
Div
import
sys
import
cv2
from
postprocess
import
SegPostprocess
client
=
Client
()
client
.
load_client_config
(
"serving_client/serving_client_conf.prototxt"
)
client
.
connect
([
"127.0.0.1:9494"
])
preprocess
=
Sequential
([
File2Image
(),
Resize
((
512
,
512
),
interpolation
=
cv2
.
INTER_LINEAR
),
Div
(
255.0
),
Normalize
([
0.5
,
0.5
,
0.5
],
[
0.5
,
0.5
,
0.5
],
False
),
Transpose
((
2
,
0
,
1
))
])
postprocess
=
SegPostprocess
(
2
)
filename
=
sys
.
argv
[
1
]
im
=
preprocess
(
filename
)
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
im
},
fetch
=
[
"transpose_1.tmp_0"
])
fetch_map
[
"filename"
]
=
filename
postprocess
(
fetch_map
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录