Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
eb05033c
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看板
提交
eb05033c
编写于
10月 13, 2021
作者:
S
ShiningZhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: the result of ocr_cpp_server is not complete
上级
072114e7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
34 deletion
+56
-34
core/general-server/op/general_detection_op.cpp
core/general-server/op/general_detection_op.cpp
+53
-31
core/general-server/op/general_detection_op.h
core/general-server/op/general_detection_op.h
+1
-1
core/predictor/tools/ocrtools/preprocess_op.cpp
core/predictor/tools/ocrtools/preprocess_op.cpp
+2
-2
未找到文件。
core/general-server/op/general_detection_op.cpp
浏览文件 @
eb05033c
...
...
@@ -191,42 +191,64 @@ int GeneralDetectionOp::inference() {
boxes
=
post_processor_
.
FilterTagDetRes
(
boxes
,
ratio_h
,
ratio_w
,
srcimg
);
for
(
int
i
=
boxes
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
crop_img
=
GetRotateCropImage
(
img
,
boxes
[
i
]);
float
wh_ratio
=
float
(
crop_img
.
cols
)
/
float
(
crop_img
.
rows
);
float
max_wh_ratio
=
0.0
f
;
std
::
vector
<
cv
::
Mat
>
crop_imgs
;
std
::
vector
<
cv
::
Mat
>
resize_imgs
;
int
max_resize_w
=
0
;
int
max_resize_h
=
0
;
int
box_num
=
boxes
.
size
();
std
::
vector
<
std
::
vector
<
float
>>
output_rec
;
for
(
int
i
=
0
;
i
<
box_num
;
++
i
)
{
cv
::
Mat
line_img
=
GetRotateCropImage
(
img
,
boxes
[
i
]);
float
wh_ratio
=
float
(
line_img
.
cols
)
/
float
(
line_img
.
rows
);
max_wh_ratio
=
max_wh_ratio
>
wh_ratio
?
max_wh_ratio
:
wh_ratio
;
crop_imgs
.
push_back
(
line_img
);
}
for
(
int
i
=
0
;
i
<
box_num
;
++
i
)
{
cv
::
Mat
resize_img
;
crop_img
=
crop_imgs
[
i
];
this
->
resize_op_rec
.
Run
(
crop_img
,
resize_img
_rec
,
wh_ratio
,
this
->
use_tensorrt_
);
crop_img
,
resize_img
,
max_
wh_ratio
,
this
->
use_tensorrt_
);
this
->
normalize_op_
.
Run
(
&
resize_img_rec
,
this
->
mean_rec
,
this
->
scale_rec
,
this
->
is_scale_
);
std
::
vector
<
float
>
output_rec
(
1
*
3
*
resize_img_rec
.
rows
*
resize_img_rec
.
cols
,
0.0
f
);
this
->
permute_op_
.
Run
(
&
resize_img_rec
,
output_rec
.
data
());
// Inference.
output_shape
=
{
1
,
3
,
resize_img_rec
.
rows
,
resize_img_rec
.
cols
};
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
databuf_size_out
=
out_num
*
sizeof
(
float
);
databuf_data_out
=
MempoolWrapper
::
instance
().
malloc
(
databuf_size_out
);
if
(
!
databuf_data_out
)
{
LOG
(
ERROR
)
<<
"Malloc failed, size: "
<<
databuf_size_out
;
return
-
1
;
}
memcpy
(
databuf_data_out
,
output_rec
.
data
(),
databuf_size_out
);
databuf_char_out
=
reinterpret_cast
<
char
*>
(
databuf_data_out
);
paddle
::
PaddleBuf
paddleBuf
(
databuf_char_out
,
databuf_size_out
);
paddle
::
PaddleTensor
tensor_out
;
tensor_out
.
name
=
"image"
;
tensor_out
.
dtype
=
paddle
::
PaddleDType
::
FLOAT32
;
tensor_out
.
shape
=
{
1
,
3
,
resize_img_rec
.
rows
,
resize_img_rec
.
cols
};
tensor_out
.
data
=
paddleBuf
;
out
->
push_back
(
tensor_out
);
&
resize_img
,
this
->
mean_rec
,
this
->
scale_rec
,
this
->
is_scale_
);
max_resize_w
=
std
::
max
(
max_resize_w
,
resize_img
.
cols
);
max_resize_h
=
std
::
max
(
max_resize_h
,
resize_img
.
rows
);
resize_imgs
.
push_back
(
resize_img
);
}
int
buf_size
=
3
*
max_resize_h
*
max_resize_w
;
output_rec
=
std
::
vector
<
std
::
vector
<
float
>>
(
box_num
,
std
::
vector
<
float
>
(
buf_size
,
0.0
f
));
for
(
int
i
=
0
;
i
<
box_num
;
++
i
)
{
resize_img_rec
=
resize_imgs
[
i
];
this
->
permute_op_
.
Run
(
&
resize_img_rec
,
output_rec
[
i
].
data
());
}
// Inference.
output_shape
=
{
box_num
,
3
,
max_resize_h
,
max_resize_w
};
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
databuf_size_out
=
out_num
*
sizeof
(
float
);
databuf_data_out
=
MempoolWrapper
::
instance
().
malloc
(
databuf_size_out
);
if
(
!
databuf_data_out
)
{
LOG
(
ERROR
)
<<
"Malloc failed, size: "
<<
databuf_size_out
;
return
-
1
;
}
int
offset
=
buf_size
*
sizeof
(
float
);
for
(
int
i
=
0
;
i
<
box_num
;
++
i
)
{
memcpy
(
databuf_data_out
+
i
*
offset
,
output_rec
[
i
].
data
(),
offset
);
}
databuf_char_out
=
reinterpret_cast
<
char
*>
(
databuf_data_out
);
paddle
::
PaddleBuf
paddleBuf
(
databuf_char_out
,
databuf_size_out
);
paddle
::
PaddleTensor
tensor_out
;
tensor_out
.
name
=
"image"
;
tensor_out
.
dtype
=
paddle
::
PaddleDType
::
FLOAT32
;
tensor_out
.
shape
=
output_shape
;
tensor_out
.
data
=
paddleBuf
;
out
->
push_back
(
tensor_out
);
}
out
->
erase
(
out
->
begin
(),
out
->
begin
()
+
infer_outnum
);
...
...
core/general-server/op/general_detection_op.h
浏览文件 @
eb05033c
...
...
@@ -63,7 +63,7 @@ class GeneralDetectionOp
double
det_db_thresh_
=
0.3
;
double
det_db_box_thresh_
=
0.5
;
double
det_db_unclip_ratio_
=
2.0
;
double
det_db_unclip_ratio_
=
1.5
;
std
::
vector
<
float
>
mean_det
=
{
0.485
f
,
0.456
f
,
0.406
f
};
std
::
vector
<
float
>
scale_det
=
{
1
/
0.229
f
,
1
/
0.224
f
,
1
/
0.225
f
};
...
...
core/predictor/tools/ocrtools/preprocess_op.cpp
浏览文件 @
eb05033c
...
...
@@ -82,14 +82,14 @@ void ResizeImgType0::Run(const cv::Mat &img, cv::Mat &resize_img,
else
if
(
resize_h
/
32
<
1
+
1e-5
)
resize_h
=
32
;
else
resize_h
=
(
resize_h
/
32
)
*
32
;
resize_h
=
(
resize_h
/
32
-
1
)
*
32
;
if
(
resize_w
%
32
==
0
)
resize_w
=
resize_w
;
else
if
(
resize_w
/
32
<
1
+
1e-5
)
resize_w
=
32
;
else
resize_w
=
(
resize_w
/
32
)
*
32
;
resize_w
=
(
resize_w
/
32
-
1
)
*
32
;
if
(
!
use_tensorrt
)
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
resize_h
));
ratio_h
=
float
(
resize_h
)
/
float
(
h
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录