Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
5b3e7a33
P
PaddleOCR
项目概览
s920243400
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5b3e7a33
编写于
5月 26, 2021
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support cpp trt predict
上级
0707f743
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
61 addition
and
37 deletion
+61
-37
deploy/cpp_infer/src/ocr_det.cpp
deploy/cpp_infer/src/ocr_det.cpp
+37
-1
deploy/cpp_infer/src/ocr_rec.cpp
deploy/cpp_infer/src/ocr_rec.cpp
+9
-0
deploy/cpp_infer/src/preprocess_op.cpp
deploy/cpp_infer/src/preprocess_op.cpp
+15
-36
未找到文件。
deploy/cpp_infer/src/ocr_det.cpp
浏览文件 @
5b3e7a33
...
...
@@ -30,6 +30,42 @@ void DBDetector::LoadModel(const std::string &model_dir) {
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
min_input_shape
=
{
{
"x"
,
{
1
,
3
,
50
,
50
}},
{
"conv2d_92.tmp_0"
,
{
1
,
96
,
20
,
20
}},
{
"conv2d_91.tmp_0"
,
{
1
,
96
,
10
,
10
}},
{
"nearest_interp_v2_1.tmp_0"
,
{
1
,
96
,
10
,
10
}},
{
"nearest_interp_v2_2.tmp_0"
,
{
1
,
96
,
20
,
20
}},
{
"nearest_interp_v2_3.tmp_0"
,
{
1
,
24
,
20
,
20
}},
{
"nearest_interp_v2_4.tmp_0"
,
{
1
,
24
,
20
,
20
}},
{
"nearest_interp_v2_5.tmp_0"
,
{
1
,
24
,
20
,
20
}},
{
"elementwise_add_7"
,
{
1
,
56
,
2
,
2
}},
{
"nearest_interp_v2_0.tmp_0"
,
{
1
,
96
,
2
,
2
}}};
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
max_input_shape
=
{
{
"x"
,
{
1
,
3
,
this
->
max_side_len_
,
this
->
max_side_len_
}},
{
"conv2d_92.tmp_0"
,
{
1
,
96
,
400
,
400
}},
{
"conv2d_91.tmp_0"
,
{
1
,
96
,
200
,
200
}},
{
"nearest_interp_v2_1.tmp_0"
,
{
1
,
96
,
200
,
200
}},
{
"nearest_interp_v2_2.tmp_0"
,
{
1
,
96
,
400
,
400
}},
{
"nearest_interp_v2_3.tmp_0"
,
{
1
,
24
,
400
,
400
}},
{
"nearest_interp_v2_4.tmp_0"
,
{
1
,
24
,
400
,
400
}},
{
"nearest_interp_v2_5.tmp_0"
,
{
1
,
24
,
400
,
400
}},
{
"elementwise_add_7"
,
{
1
,
56
,
400
,
400
}},
{
"nearest_interp_v2_0.tmp_0"
,
{
1
,
96
,
400
,
400
}}};
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
opt_input_shape
=
{
{
"x"
,
{
1
,
3
,
640
,
640
}},
{
"conv2d_92.tmp_0"
,
{
1
,
96
,
160
,
160
}},
{
"conv2d_91.tmp_0"
,
{
1
,
96
,
80
,
80
}},
{
"nearest_interp_v2_1.tmp_0"
,
{
1
,
96
,
80
,
80
}},
{
"nearest_interp_v2_2.tmp_0"
,
{
1
,
96
,
160
,
160
}},
{
"nearest_interp_v2_3.tmp_0"
,
{
1
,
24
,
160
,
160
}},
{
"nearest_interp_v2_4.tmp_0"
,
{
1
,
24
,
160
,
160
}},
{
"nearest_interp_v2_5.tmp_0"
,
{
1
,
24
,
160
,
160
}},
{
"elementwise_add_7"
,
{
1
,
56
,
40
,
40
}},
{
"nearest_interp_v2_0.tmp_0"
,
{
1
,
96
,
40
,
40
}}};
config
.
SetTRTDynamicShapeInfo
(
min_input_shape
,
max_input_shape
,
opt_input_shape
);
}
}
else
{
config
.
DisableGpu
();
...
...
@@ -48,7 +84,7 @@ void DBDetector::LoadModel(const std::string &model_dir) {
config
.
SwitchIrOptim
(
true
);
config
.
EnableMemoryOptim
();
config
.
DisableGlogInfo
();
//
config.DisableGlogInfo();
this
->
predictor_
=
CreatePredictor
(
config
);
}
...
...
deploy/cpp_infer/src/ocr_rec.cpp
浏览文件 @
5b3e7a33
...
...
@@ -105,6 +105,15 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
min_input_shape
=
{
{
"x"
,
{
1
,
3
,
32
,
10
}}};
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
max_input_shape
=
{
{
"x"
,
{
1
,
3
,
32
,
2000
}}};
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>
opt_input_shape
=
{
{
"x"
,
{
1
,
3
,
32
,
320
}}};
config
.
SetTRTDynamicShapeInfo
(
min_input_shape
,
max_input_shape
,
opt_input_shape
);
}
}
else
{
config
.
DisableGpu
();
...
...
deploy/cpp_infer/src/preprocess_op.cpp
100755 → 100644
浏览文件 @
5b3e7a33
...
...
@@ -81,15 +81,9 @@ void ResizeImgType0::Run(const cv::Mat &img, cv::Mat &resize_img,
resize_h
=
max
(
int
(
round
(
float
(
resize_h
)
/
32
)
*
32
),
32
);
resize_w
=
max
(
int
(
round
(
float
(
resize_w
)
/
32
)
*
32
),
32
);
if
(
!
use_tensorrt
)
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
resize_h
));
ratio_h
=
float
(
resize_h
)
/
float
(
h
);
ratio_w
=
float
(
resize_w
)
/
float
(
w
);
}
else
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
640
,
640
));
ratio_h
=
float
(
640
)
/
float
(
h
);
ratio_w
=
float
(
640
)
/
float
(
w
);
}
}
void
CrnnResizeImg
::
Run
(
const
cv
::
Mat
&
img
,
cv
::
Mat
&
resize_img
,
float
wh_ratio
,
...
...
@@ -108,23 +102,12 @@ void CrnnResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img, float wh_ratio,
resize_w
=
imgW
;
else
resize_w
=
int
(
ceilf
(
imgH
*
ratio
));
if
(
!
use_tensorrt
)
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
imgH
),
0.
f
,
0.
f
,
cv
::
INTER_LINEAR
);
cv
::
copyMakeBorder
(
resize_img
,
resize_img
,
0
,
0
,
0
,
int
(
imgW
-
resize_img
.
cols
),
cv
::
BORDER_CONSTANT
,
{
127
,
127
,
127
});
}
else
{
int
k
=
int
(
img
.
cols
*
32
/
img
.
rows
);
if
(
k
>=
100
)
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
100
,
32
),
0.
f
,
0.
f
,
cv
::
INTER_LINEAR
);
}
else
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
k
,
32
),
0.
f
,
0.
f
,
cv
::
INTER_LINEAR
);
cv
::
copyMakeBorder
(
resize_img
,
resize_img
,
0
,
0
,
0
,
int
(
100
-
k
),
cv
::
BORDER_CONSTANT
,
{
127
,
127
,
127
});
}
}
}
void
ClsResizeImg
::
Run
(
const
cv
::
Mat
&
img
,
cv
::
Mat
&
resize_img
,
...
...
@@ -142,16 +125,12 @@ void ClsResizeImg::Run(const cv::Mat &img, cv::Mat &resize_img,
else
resize_w
=
int
(
ceilf
(
imgH
*
ratio
));
if
(
!
use_tensorrt
)
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
imgH
),
0.
f
,
0.
f
,
cv
::
INTER_LINEAR
);
if
(
resize_w
<
imgW
)
{
cv
::
copyMakeBorder
(
resize_img
,
resize_img
,
0
,
0
,
0
,
imgW
-
resize_w
,
cv
::
BORDER_CONSTANT
,
cv
::
Scalar
(
0
,
0
,
0
));
}
}
else
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
100
,
32
),
0.
f
,
0.
f
,
cv
::
INTER_LINEAR
);
}
}
}
// namespace PaddleOCR
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录