Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
6ca25e25
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6ca25e25
编写于
11月 09, 2021
作者:
S
stephon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix serving bug of picodet
上级
67d982c3
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
36 addition
and
25 deletion
+36
-25
deploy/paddleserving/recognition/recognition_web_service.py
deploy/paddleserving/recognition/recognition_web_service.py
+36
-25
未找到文件。
deploy/paddleserving/recognition/recognition_web_service.py
浏览文件 @
6ca25e25
...
...
@@ -23,6 +23,7 @@ import faiss
import
pickle
import
json
class
DetOp
(
Op
):
def
init_op
(
self
):
self
.
img_preprocess
=
Sequential
([
...
...
@@ -65,22 +66,28 @@ class DetOp(Op):
imgs
.
append
({
"image"
:
im
[
np
.
newaxis
,
:],
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
)[
np
.
newaxis
,:],
"scale_factor"
:
np
.
array
([
im_scale_y
,
im_scale_x
]).
astype
(
'float32'
),
"im_shape"
:
np
.
array
(
list
(
im
.
shape
[
1
:])).
reshape
(
-
1
)[
np
.
newaxis
,
:],
"scale_factor"
:
np
.
array
([
im_scale_y
,
im_scale_x
]).
reshape
(
-
1
)[
np
.
newaxis
,
:],
})
self
.
raw_img
=
raw_imgs
feed_dict
=
{
"image"
:
np
.
concatenate
([
x
[
"image"
]
for
x
in
imgs
],
axis
=
0
),
"im_shape"
:
np
.
concatenate
([
x
[
"im_shape"
]
for
x
in
imgs
],
axis
=
0
),
"scale_factor"
:
np
.
concatenate
([
x
[
"scale_factor"
]
for
x
in
imgs
],
axis
=
0
)
"image"
:
np
.
concatenate
(
[
x
[
"image"
]
for
x
in
imgs
],
axis
=
0
),
"im_shape"
:
np
.
concatenate
(
[
x
[
"im_shape"
]
for
x
in
imgs
],
axis
=
0
),
"scale_factor"
:
np
.
concatenate
(
[
x
[
"scale_factor"
]
for
x
in
imgs
],
axis
=
0
)
}
return
feed_dict
,
False
,
None
,
""
def
postprocess
(
self
,
input_dicts
,
fetch_dict
,
log_id
):
boxes
=
self
.
img_postprocess
(
fetch_dict
,
visualize
=
False
)
boxes
.
sort
(
key
=
lambda
x
:
x
[
"score"
],
reverse
=
True
)
boxes
=
filter
(
lambda
x
:
x
[
"score"
]
>=
self
.
threshold
,
boxes
[:
self
.
max_det_results
])
boxes
.
sort
(
key
=
lambda
x
:
x
[
"score"
],
reverse
=
True
)
boxes
=
filter
(
lambda
x
:
x
[
"score"
]
>=
self
.
threshold
,
boxes
[:
self
.
max_det_results
])
boxes
=
list
(
boxes
)
for
i
in
range
(
len
(
boxes
)):
boxes
[
i
][
"bbox"
][
2
]
+=
boxes
[
i
][
"bbox"
][
0
]
-
1
...
...
@@ -89,11 +96,12 @@ class DetOp(Op):
res_dict
=
{
"bbox_result"
:
result
,
"image"
:
self
.
raw_img
}
return
res_dict
,
None
,
""
class
RecOp
(
Op
):
def
init_op
(
self
):
self
.
seq
=
Sequential
([
BGR2RGB
(),
Resize
((
224
,
224
)),
Div
(
255
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
BGR2RGB
(),
Resize
((
224
,
224
)),
Div
(
255
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
False
),
Transpose
((
2
,
0
,
1
))
])
...
...
@@ -121,7 +129,8 @@ class RecOp(Op):
origin_img
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
dt_boxes
=
input_dict
[
"bbox_result"
]
boxes
=
json
.
loads
(
dt_boxes
)
boxes
.
append
({
"category_id"
:
0
,
boxes
.
append
({
"category_id"
:
0
,
"score"
:
1.0
,
"bbox"
:
[
0
,
0
,
origin_img
.
shape
[
1
],
origin_img
.
shape
[
0
]]
})
...
...
@@ -131,14 +140,14 @@ class RecOp(Op):
imgs
=
[]
for
box
in
boxes
:
box
=
[
int
(
x
)
for
x
in
box
[
"bbox"
]]
im
=
origin_img
[
box
[
1
]:
box
[
3
],
box
[
0
]:
box
[
2
]].
copy
()
im
=
origin_img
[
box
[
1
]:
box
[
3
],
box
[
0
]:
box
[
2
]].
copy
()
img
=
self
.
seq
(
im
)
imgs
.
append
(
img
[
np
.
newaxis
,
:].
copy
())
input_imgs
=
np
.
concatenate
(
imgs
,
axis
=
0
)
return
{
"x"
:
input_imgs
},
False
,
None
,
""
def
nms_to_rec_results
(
self
,
results
,
thresh
=
0.1
):
def
nms_to_rec_results
(
self
,
results
,
thresh
=
0.1
):
filtered_results
=
[]
x1
=
np
.
array
([
r
[
"bbox"
][
0
]
for
r
in
results
]).
astype
(
"float32"
)
y1
=
np
.
array
([
r
[
"bbox"
][
1
]
for
r
in
results
]).
astype
(
"float32"
)
...
...
@@ -187,12 +196,14 @@ class RecOp(Op):
results
=
self
.
nms_to_rec_results
(
results
,
self
.
rec_nms_thresold
)
return
{
"result"
:
str
(
results
)},
None
,
""
class
RecognitionService
(
WebService
):
def
get_pipeline_response
(
self
,
read_op
):
det_op
=
DetOp
(
name
=
"det"
,
input_ops
=
[
read_op
])
rec_op
=
RecOp
(
name
=
"rec"
,
input_ops
=
[
det_op
])
return
rec_op
product_recog_service
=
RecognitionService
(
name
=
"recognition"
)
product_recog_service
.
prepare_pipeline_config
(
"config.yml"
)
product_recog_service
.
run_service
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录