Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
7cf64ce4
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看板
提交
7cf64ce4
编写于
9月 26, 2021
作者:
S
stephon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some bugs; same as paddle inference result
上级
55495b69
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
8 deletion
+20
-8
deploy/paddleserving/recognition/recognition_web_service.py
deploy/paddleserving/recognition/recognition_web_service.py
+20
-8
未找到文件。
deploy/paddleserving/recognition/recognition_web_service.py
浏览文件 @
7cf64ce4
...
...
@@ -81,16 +81,20 @@ class DetOp(Op):
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
])
result
=
json
.
dumps
(
list
(
boxes
))
res_dict
=
{
"bbox_result"
:
result
,
"image"
:
self
.
raw_img
}
boxes
=
list
(
boxes
)
for
i
in
range
(
len
(
boxes
)):
boxes
[
i
][
"bbox"
][
2
]
+=
boxes
[
i
][
"bbox"
][
0
]
-
1
boxes
[
i
][
"bbox"
][
3
]
+=
boxes
[
i
][
"bbox"
][
1
]
-
1
result
=
json
.
dumps
(
boxes
)
res_dict
=
{
"bbox_result"
:
result
,
"image"
:
self
.
raw_img
}
return
res_dict
,
None
,
""
class
RecOp
(
Op
):
def
init_op
(
self
):
self
.
seq
=
Sequential
([
Resize
(
256
),
CenterCrop
(
224
),
RGB2BGR
(),
Transpose
((
2
,
0
,
1
)),
BGR2RGB
(),
Resize
((
224
,
224
)),
Div
(
255
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
],
True
)
False
),
Transpose
((
2
,
0
,
1
)
)
])
index_dir
=
"../../recognition_demo_data_v1.1/gallery_product/index"
...
...
@@ -107,6 +111,8 @@ class RecOp(Op):
self
.
rec_nms_thresold
=
0.05
self
.
rec_score_thres
=
0.5
self
.
feature_normalize
=
True
self
.
return_k
=
1
def
preprocess
(
self
,
input_dicts
,
data_id
,
log_id
):
(
_
,
input_dict
),
=
input_dicts
.
items
()
...
...
@@ -125,7 +131,7 @@ class RecOp(Op):
imgs
=
[]
for
box
in
boxes
:
box
=
[
int
(
x
)
for
x
in
box
[
"bbox"
]]
im
=
origin_img
[
box
[
1
]:
box
[
1
]
+
box
[
3
],
box
[
0
]:
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
())
...
...
@@ -159,14 +165,20 @@ class RecOp(Op):
return
filtered_results
def
postprocess
(
self
,
input_dicts
,
fetch_dict
,
log_id
):
score_list
=
fetch_dict
[
"features"
]
scores
,
docs
=
self
.
searcher
.
search
(
score_list
,
1
)
batch_features
=
fetch_dict
[
"features"
]
if
self
.
feature_normalize
:
feas_norm
=
np
.
sqrt
(
np
.
sum
(
np
.
square
(
batch_features
),
axis
=
1
,
keepdims
=
True
))
batch_features
=
np
.
divide
(
batch_features
,
feas_norm
)
scores
,
docs
=
self
.
searcher
.
search
(
batch_features
,
self
.
return_k
)
results
=
[]
for
i
in
range
(
scores
.
shape
[
0
]):
pred
=
{}
if
scores
[
i
][
0
]
>=
self
.
rec_score_thres
:
pred
[
"bbox"
]
=
self
.
det_boxes
[
i
][
"bbox"
]
pred
[
"bbox"
]
=
[
int
(
x
)
for
x
in
self
.
det_boxes
[
i
][
"bbox"
]
]
pred
[
"rec_docs"
]
=
self
.
id_map
[
docs
[
i
][
0
]].
split
()[
1
]
pred
[
"rec_scores"
]
=
scores
[
i
][
0
]
results
.
append
(
pred
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录