Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
ff7774a4
S
Serving
项目概览
PaddlePaddle
/
Serving
1 年多 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ff7774a4
编写于
4月 27, 2021
作者:
T
TeslaZhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support mini-batch in Pipeline mode
上级
567dc666
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
267 addition
and
171 deletion
+267
-171
python/examples/pipeline/ocr/web_service.py
python/examples/pipeline/ocr/web_service.py
+69
-7
python/pipeline/operator.py
python/pipeline/operator.py
+198
-164
未找到文件。
python/examples/pipeline/ocr/web_service.py
浏览文件 @
ff7774a4
...
@@ -79,6 +79,9 @@ class RecOp(Op):
...
@@ -79,6 +79,9 @@ class RecOp(Op):
feed_list
=
[]
feed_list
=
[]
img_list
=
[]
img_list
=
[]
max_wh_ratio
=
0
max_wh_ratio
=
0
## One batch, the type of feed_data is dict.
"""
for i, dtbox in enumerate(dt_boxes):
for i, dtbox in enumerate(dt_boxes):
boximg = self.get_rotate_crop_image(im, dt_boxes[i])
boximg = self.get_rotate_crop_image(im, dt_boxes[i])
img_list.append(boximg)
img_list.append(boximg)
...
@@ -92,14 +95,73 @@ class RecOp(Op):
...
@@ -92,14 +95,73 @@ class RecOp(Op):
norm_img = self.ocr_reader.resize_norm_img(img, max_wh_ratio)
norm_img = self.ocr_reader.resize_norm_img(img, max_wh_ratio)
imgs[id] = norm_img
imgs[id] = norm_img
feed = {"image": imgs.copy()}
feed = {"image": imgs.copy()}
return
feed
,
False
,
None
,
""
def
postprocess
(
self
,
input_dicts
,
fetch_dict
,
log_id
):
"""
rec_res
=
self
.
ocr_reader
.
postprocess
(
fetch_dict
,
with_score
=
True
)
res_lst
=
[]
## Many mini-batchs, the type of feed_data is list.
for
res
in
rec_res
:
max_batch_size
=
6
# len(dt_boxes)
res_lst
.
append
(
res
[
0
])
res
=
{
"res"
:
str
(
res_lst
)}
# If max_batch_size is 0, skipping predict stage
if
max_batch_size
==
0
:
return
{},
True
,
None
,
""
boxes_size
=
len
(
dt_boxes
)
batch_size
=
boxes_size
//
max_batch_size
rem
=
boxes_size
%
max_batch_size
#_LOGGER.info("max_batch_len:{}, batch_size:{}, rem:{}, boxes_size:{}".format(max_batch_size, batch_size, rem, boxes_size))
for
bt_idx
in
range
(
0
,
batch_size
+
1
):
imgs
=
None
boxes_num_in_one_batch
=
0
if
bt_idx
==
batch_size
:
if
rem
==
0
:
continue
else
:
boxes_num_in_one_batch
=
rem
elif
bt_idx
<
batch_size
:
boxes_num_in_one_batch
=
max_batch_size
else
:
_LOGGER
.
error
(
"batch_size error, bt_idx={}, batch_size={}"
.
format
(
bt_idx
,
batch_size
))
break
start
=
bt_idx
*
max_batch_size
end
=
start
+
boxes_num_in_one_batch
img_list
=
[]
for
box_idx
in
range
(
start
,
end
):
boximg
=
self
.
get_rotate_crop_image
(
im
,
dt_boxes
[
box_idx
])
img_list
.
append
(
boximg
)
h
,
w
=
boximg
.
shape
[
0
:
2
]
wh_ratio
=
w
*
1.0
/
h
max_wh_ratio
=
max
(
max_wh_ratio
,
wh_ratio
)
_
,
w
,
h
=
self
.
ocr_reader
.
resize_norm_img
(
img_list
[
0
],
max_wh_ratio
).
shape
#_LOGGER.info("---- idx:{}, w:{}, h:{}".format(bt_idx, w, h))
imgs
=
np
.
zeros
((
boxes_num_in_one_batch
,
3
,
w
,
h
)).
astype
(
'float32'
)
for
id
,
img
in
enumerate
(
img_list
):
norm_img
=
self
.
ocr_reader
.
resize_norm_img
(
img
,
max_wh_ratio
)
imgs
[
id
]
=
norm_img
feed
=
{
"image"
:
imgs
.
copy
()}
feed_list
.
append
(
feed
)
#_LOGGER.info("feed_list : {}".format(feed_list))
return
feed_list
,
False
,
None
,
""
def
postprocess
(
self
,
input_dicts
,
fetch_data
,
log_id
):
res_list
=
[]
if
isinstance
(
fetch_data
,
dict
):
if
len
(
fetch_data
)
>
0
:
rec_batch_res
=
self
.
ocr_reader
.
postprocess
(
fetch_data
,
with_score
=
True
)
for
res
in
rec_batch_res
:
res_list
.
append
(
res
[
0
])
elif
isinstance
(
fetch_data
,
list
):
for
one_batch
in
fetch_data
:
one_batch_res
=
self
.
ocr_reader
.
postprocess
(
one_batch
,
with_score
=
True
)
for
res
in
one_batch_res
:
res_list
.
append
(
res
[
0
])
res
=
{
"res"
:
str
(
res_list
)}
return
res
,
None
,
""
return
res
,
None
,
""
...
...
python/pipeline/operator.py
浏览文件 @
ff7774a4
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录