Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
ae80a832
P
PaddleOCR
项目概览
weixin_41840029
/
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看板
提交
ae80a832
编写于
12月 27, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tensorrt predict for cpp_infer demo
上级
ed600b30
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
57 addition
and
13 deletion
+57
-13
deploy/cpp_infer/include/config.h
deploy/cpp_infer/include/config.h
+8
-0
deploy/cpp_infer/include/ocr_cls.h
deploy/cpp_infer/include/ocr_cls.h
+6
-2
deploy/cpp_infer/include/ocr_det.h
deploy/cpp_infer/include/ocr_det.h
+6
-1
deploy/cpp_infer/include/ocr_rec.h
deploy/cpp_infer/include/ocr_rec.h
+6
-2
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+5
-3
deploy/cpp_infer/src/ocr_cls.cpp
deploy/cpp_infer/src/ocr_cls.cpp
+8
-1
deploy/cpp_infer/src/ocr_det.cpp
deploy/cpp_infer/src/ocr_det.cpp
+7
-4
deploy/cpp_infer/src/ocr_rec.cpp
deploy/cpp_infer/src/ocr_rec.cpp
+7
-0
deploy/cpp_infer/tools/config.txt
deploy/cpp_infer/tools/config.txt
+4
-0
未找到文件。
deploy/cpp_infer/include/config.h
浏览文件 @
ae80a832
...
@@ -62,6 +62,10 @@ public:
...
@@ -62,6 +62,10 @@ public:
this
->
cls_thresh
=
stod
(
config_map_
[
"cls_thresh"
]);
this
->
cls_thresh
=
stod
(
config_map_
[
"cls_thresh"
]);
this
->
visualize
=
bool
(
stoi
(
config_map_
[
"visualize"
]));
this
->
visualize
=
bool
(
stoi
(
config_map_
[
"visualize"
]));
this
->
use_tensorrt
=
bool
(
stoi
(
config_map_
[
"use_tensorrt"
]));
this
->
use_fp16
=
bool
(
stod
(
config_map_
[
"use_fp16"
]));
}
}
bool
use_gpu
=
false
;
bool
use_gpu
=
false
;
...
@@ -96,6 +100,10 @@ public:
...
@@ -96,6 +100,10 @@ public:
bool
visualize
=
true
;
bool
visualize
=
true
;
bool
use_tensorrt
=
false
;
bool
use_fp16
=
false
;
void
PrintConfigInfo
();
void
PrintConfigInfo
();
private:
private:
...
...
deploy/cpp_infer/include/ocr_cls.h
浏览文件 @
ae80a832
...
@@ -39,7 +39,8 @@ public:
...
@@ -39,7 +39,8 @@ public:
explicit
Classifier
(
const
std
::
string
&
model_dir
,
const
bool
&
use_gpu
,
explicit
Classifier
(
const
std
::
string
&
model_dir
,
const
bool
&
use_gpu
,
const
int
&
gpu_id
,
const
int
&
gpu_mem
,
const
int
&
gpu_id
,
const
int
&
gpu_mem
,
const
int
&
cpu_math_library_num_threads
,
const
int
&
cpu_math_library_num_threads
,
const
bool
&
use_mkldnn
,
const
double
&
cls_thresh
)
{
const
bool
&
use_mkldnn
,
const
double
&
cls_thresh
,
const
bool
&
use_tensorrt
,
const
&
bool
use_fp16
)
{
this
->
use_gpu_
=
use_gpu
;
this
->
use_gpu_
=
use_gpu
;
this
->
gpu_id_
=
gpu_id
;
this
->
gpu_id_
=
gpu_id
;
this
->
gpu_mem_
=
gpu_mem
;
this
->
gpu_mem_
=
gpu_mem
;
...
@@ -47,6 +48,8 @@ public:
...
@@ -47,6 +48,8 @@ public:
this
->
use_mkldnn_
=
use_mkldnn
;
this
->
use_mkldnn_
=
use_mkldnn
;
this
->
cls_thresh
=
cls_thresh
;
this
->
cls_thresh
=
cls_thresh
;
this
->
use_tensorrt_
=
use_tensorrt
;
this
->
use_fp16_
=
use_fp16
;
LoadModel
(
model_dir
);
LoadModel
(
model_dir
);
}
}
...
@@ -69,7 +72,8 @@ private:
...
@@ -69,7 +72,8 @@ private:
std
::
vector
<
float
>
mean_
=
{
0.5
f
,
0.5
f
,
0.5
f
};
std
::
vector
<
float
>
mean_
=
{
0.5
f
,
0.5
f
,
0.5
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.5
f
,
1
/
0.5
f
,
1
/
0.5
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.5
f
,
1
/
0.5
f
,
1
/
0.5
f
};
bool
is_scale_
=
true
;
bool
is_scale_
=
true
;
bool
use_tensorrt_
=
false
;
bool
use_fp16_
=
false
;
// pre-process
// pre-process
ClsResizeImg
resize_op_
;
ClsResizeImg
resize_op_
;
Normalize
normalize_op_
;
Normalize
normalize_op_
;
...
...
deploy/cpp_infer/include/ocr_det.h
浏览文件 @
ae80a832
...
@@ -45,7 +45,8 @@ public:
...
@@ -45,7 +45,8 @@ public:
const
double
&
det_db_thresh
,
const
double
&
det_db_thresh
,
const
double
&
det_db_box_thresh
,
const
double
&
det_db_box_thresh
,
const
double
&
det_db_unclip_ratio
,
const
double
&
det_db_unclip_ratio
,
const
bool
&
visualize
)
{
const
bool
&
visualize
const
bool
&
use_tensorrt
,
const
bool
&
use_fp16
)
{
this
->
use_gpu_
=
use_gpu
;
this
->
use_gpu_
=
use_gpu
;
this
->
gpu_id_
=
gpu_id
;
this
->
gpu_id_
=
gpu_id
;
this
->
gpu_mem_
=
gpu_mem
;
this
->
gpu_mem_
=
gpu_mem
;
...
@@ -59,6 +60,8 @@ public:
...
@@ -59,6 +60,8 @@ public:
this
->
det_db_unclip_ratio_
=
det_db_unclip_ratio
;
this
->
det_db_unclip_ratio_
=
det_db_unclip_ratio
;
this
->
visualize_
=
visualize
;
this
->
visualize_
=
visualize
;
this
->
use_tensorrt_
=
use_tensorrt
;
this
->
use_fp16_
=
use_fp16
;
LoadModel
(
model_dir
);
LoadModel
(
model_dir
);
}
}
...
@@ -85,6 +88,8 @@ private:
...
@@ -85,6 +88,8 @@ private:
double
det_db_unclip_ratio_
=
2.0
;
double
det_db_unclip_ratio_
=
2.0
;
bool
visualize_
=
true
;
bool
visualize_
=
true
;
bool
use_tensorrt_
=
false
;
bool
use_fp16_
=
false
;
std
::
vector
<
float
>
mean_
=
{
0.485
f
,
0.456
f
,
0.406
f
};
std
::
vector
<
float
>
mean_
=
{
0.485
f
,
0.456
f
,
0.406
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.229
f
,
1
/
0.224
f
,
1
/
0.225
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.229
f
,
1
/
0.224
f
,
1
/
0.225
f
};
...
...
deploy/cpp_infer/include/ocr_rec.h
浏览文件 @
ae80a832
...
@@ -41,12 +41,15 @@ public:
...
@@ -41,12 +41,15 @@ public:
explicit
CRNNRecognizer
(
const
std
::
string
&
model_dir
,
const
bool
&
use_gpu
,
explicit
CRNNRecognizer
(
const
std
::
string
&
model_dir
,
const
bool
&
use_gpu
,
const
int
&
gpu_id
,
const
int
&
gpu_mem
,
const
int
&
gpu_id
,
const
int
&
gpu_mem
,
const
int
&
cpu_math_library_num_threads
,
const
int
&
cpu_math_library_num_threads
,
const
bool
&
use_mkldnn
,
const
string
&
label_path
)
{
const
bool
&
use_mkldnn
,
const
string
&
label_path
,
const
bool
&
use_tensorrt
,
const
bool
&
use_fp16
)
{
this
->
use_gpu_
=
use_gpu
;
this
->
use_gpu_
=
use_gpu
;
this
->
gpu_id_
=
gpu_id
;
this
->
gpu_id_
=
gpu_id
;
this
->
gpu_mem_
=
gpu_mem
;
this
->
gpu_mem_
=
gpu_mem
;
this
->
cpu_math_library_num_threads_
=
cpu_math_library_num_threads
;
this
->
cpu_math_library_num_threads_
=
cpu_math_library_num_threads
;
this
->
use_mkldnn_
=
use_mkldnn
;
this
->
use_mkldnn_
=
use_mkldnn
;
this
->
use_tensorrt_
=
use_tensorrt
;
this
->
use_fp16_
=
use_fp16
;
this
->
label_list_
=
Utility
::
ReadDict
(
label_path
);
this
->
label_list_
=
Utility
::
ReadDict
(
label_path
);
this
->
label_list_
.
insert
(
this
->
label_list_
.
begin
(),
this
->
label_list_
.
insert
(
this
->
label_list_
.
begin
(),
...
@@ -76,7 +79,8 @@ private:
...
@@ -76,7 +79,8 @@ private:
std
::
vector
<
float
>
mean_
=
{
0.5
f
,
0.5
f
,
0.5
f
};
std
::
vector
<
float
>
mean_
=
{
0.5
f
,
0.5
f
,
0.5
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.5
f
,
1
/
0.5
f
,
1
/
0.5
f
};
std
::
vector
<
float
>
scale_
=
{
1
/
0.5
f
,
1
/
0.5
f
,
1
/
0.5
f
};
bool
is_scale_
=
true
;
bool
is_scale_
=
true
;
bool
use_tensorrt_
=
false
;
bool
use_fp16_
=
false
;
// pre-process
// pre-process
CrnnResizeImg
resize_op_
;
CrnnResizeImg
resize_op_
;
Normalize
normalize_op_
;
Normalize
normalize_op_
;
...
...
deploy/cpp_infer/src/main.cpp
浏览文件 @
ae80a832
...
@@ -54,18 +54,20 @@ int main(int argc, char **argv) {
...
@@ -54,18 +54,20 @@ int main(int argc, char **argv) {
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
use_mkldnn
,
config
.
max_side_len
,
config
.
det_db_thresh
,
config
.
use_mkldnn
,
config
.
max_side_len
,
config
.
det_db_thresh
,
config
.
det_db_box_thresh
,
config
.
det_db_unclip_ratio
,
config
.
det_db_box_thresh
,
config
.
det_db_unclip_ratio
,
config
.
visualize
);
config
.
visualize
,
config
.
use_tensorrt
,
config
.
use_fp16
);
Classifier
*
cls
=
nullptr
;
Classifier
*
cls
=
nullptr
;
if
(
config
.
use_angle_cls
==
true
)
{
if
(
config
.
use_angle_cls
==
true
)
{
cls
=
new
Classifier
(
config
.
cls_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
cls
=
new
Classifier
(
config
.
cls_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
use_mkldnn
,
config
.
cls_thresh
);
config
.
use_mkldnn
,
config
.
cls_thresh
,
config
.
use_tensorrt
,
config
.
use_fp16
);
}
}
CRNNRecognizer
rec
(
config
.
rec_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
CRNNRecognizer
rec
(
config
.
rec_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
use_mkldnn
,
config
.
char_list_file
);
config
.
use_mkldnn
,
config
.
char_list_file
,
config
.
use_tensorrt
,
config
.
use_fp16
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
auto
start
=
std
::
chrono
::
system_clock
::
now
();
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
boxes
;
...
...
deploy/cpp_infer/src/ocr_cls.cpp
浏览文件 @
ae80a832
...
@@ -76,12 +76,19 @@ void Classifier::LoadModel(const std::string &model_dir) {
...
@@ -76,12 +76,19 @@ void Classifier::LoadModel(const std::string &model_dir) {
if
(
this
->
use_gpu_
)
{
if
(
this
->
use_gpu_
)
{
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
if
(
this
->
use_tensorrt_
)
{
config
.
EnableTensorRtEngine
(
1
<<
20
,
10
,
3
,
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
}
}
else
{
}
else
{
config
.
DisableGpu
();
config
.
DisableGpu
();
if
(
this
->
use_mkldnn_
)
{
if
(
this
->
use_mkldnn_
)
{
config
.
EnableMKLDNN
();
config
.
EnableMKLDNN
();
}
}
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
)
;
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
)
}
}
// false for zero copy tensor
// false for zero copy tensor
...
...
deploy/cpp_infer/src/ocr_det.cpp
浏览文件 @
ae80a832
...
@@ -24,10 +24,13 @@ void DBDetector::LoadModel(const std::string &model_dir) {
...
@@ -24,10 +24,13 @@ void DBDetector::LoadModel(const std::string &model_dir) {
if
(
this
->
use_gpu_
)
{
if
(
this
->
use_gpu_
)
{
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
// config.EnableTensorRtEngine(
if
(
this
->
use_tensorrt_
)
{
// 1 << 20, 1, 3,
config
.
EnableTensorRtEngine
(
// AnalysisConfig::Precision::kFloat32,
1
<<
20
,
10
,
3
,
// false, false);
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
}
}
else
{
}
else
{
config
.
DisableGpu
();
config
.
DisableGpu
();
if
(
this
->
use_mkldnn_
)
{
if
(
this
->
use_mkldnn_
)
{
...
...
deploy/cpp_infer/src/ocr_rec.cpp
浏览文件 @
ae80a832
...
@@ -99,6 +99,13 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
...
@@ -99,6 +99,13 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
if
(
this
->
use_gpu_
)
{
if
(
this
->
use_gpu_
)
{
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
config
.
EnableUseGpu
(
this
->
gpu_mem_
,
this
->
gpu_id_
);
if
(
this
->
use_tensorrt_
)
{
config
.
EnableTensorRtEngine
(
1
<<
20
,
10
,
3
,
this
->
use_fp16_
?
paddle_infer
::
Config
::
Precision
::
kHalf
:
paddle_infer
::
Config
::
Precision
::
kFloat32
,
false
,
false
);
}
}
else
{
}
else
{
config
.
DisableGpu
();
config
.
DisableGpu
();
if
(
this
->
use_mkldnn_
)
{
if
(
this
->
use_mkldnn_
)
{
...
...
deploy/cpp_infer/tools/config.txt
浏览文件 @
ae80a832
...
@@ -24,3 +24,7 @@ char_list_file ../../ppocr/utils/ppocr_keys_v1.txt
...
@@ -24,3 +24,7 @@ char_list_file ../../ppocr/utils/ppocr_keys_v1.txt
# show the detection results
# show the detection results
visualize 1
visualize 1
# use_tensorrt
use_tensorrt 0
use_fp16 0
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录