Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
551377a0
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看板
提交
551377a0
编写于
12月 21, 2020
作者:
L
LDOUBLEV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update cpp_infer to 2.0
上级
d407cf92
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
66 addition
and
103 deletion
+66
-103
deploy/cpp_infer/include/config.h
deploy/cpp_infer/include/config.h
+2
-6
deploy/cpp_infer/include/ocr_cls.h
deploy/cpp_infer/include/ocr_cls.h
+4
-5
deploy/cpp_infer/include/ocr_det.h
deploy/cpp_infer/include/ocr_det.h
+5
-5
deploy/cpp_infer/include/ocr_rec.h
deploy/cpp_infer/include/ocr_rec.h
+4
-5
deploy/cpp_infer/src/config.cpp
deploy/cpp_infer/src/config.cpp
+4
-4
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+8
-10
deploy/cpp_infer/src/ocr_cls.cpp
deploy/cpp_infer/src/ocr_cls.cpp
+9
-19
deploy/cpp_infer/src/ocr_det.cpp
deploy/cpp_infer/src/ocr_det.cpp
+16
-23
deploy/cpp_infer/src/ocr_rec.cpp
deploy/cpp_infer/src/ocr_rec.cpp
+11
-22
deploy/cpp_infer/tools/config.txt
deploy/cpp_infer/tools/config.txt
+3
-4
未找到文件。
deploy/cpp_infer/include/config.h
浏览文件 @
551377a0
...
@@ -25,9 +25,9 @@
...
@@ -25,9 +25,9 @@
namespace
PaddleOCR
{
namespace
PaddleOCR
{
class
Config
{
class
OCR
Config
{
public:
public:
explicit
Config
(
const
std
::
string
&
config_file
)
{
explicit
OCR
Config
(
const
std
::
string
&
config_file
)
{
config_map_
=
LoadConfig
(
config_file
);
config_map_
=
LoadConfig
(
config_file
);
this
->
use_gpu
=
bool
(
stoi
(
config_map_
[
"use_gpu"
]));
this
->
use_gpu
=
bool
(
stoi
(
config_map_
[
"use_gpu"
]));
...
@@ -41,8 +41,6 @@ public:
...
@@ -41,8 +41,6 @@ public:
this
->
use_mkldnn
=
bool
(
stoi
(
config_map_
[
"use_mkldnn"
]));
this
->
use_mkldnn
=
bool
(
stoi
(
config_map_
[
"use_mkldnn"
]));
this
->
use_zero_copy_run
=
bool
(
stoi
(
config_map_
[
"use_zero_copy_run"
]));
this
->
max_side_len
=
stoi
(
config_map_
[
"max_side_len"
]);
this
->
max_side_len
=
stoi
(
config_map_
[
"max_side_len"
]);
this
->
det_db_thresh
=
stod
(
config_map_
[
"det_db_thresh"
]);
this
->
det_db_thresh
=
stod
(
config_map_
[
"det_db_thresh"
]);
...
@@ -76,8 +74,6 @@ public:
...
@@ -76,8 +74,6 @@ public:
bool
use_mkldnn
=
false
;
bool
use_mkldnn
=
false
;
bool
use_zero_copy_run
=
false
;
int
max_side_len
=
960
;
int
max_side_len
=
960
;
double
det_db_thresh
=
0.3
;
double
det_db_thresh
=
0.3
;
...
...
deploy/cpp_infer/include/ocr_cls.h
浏览文件 @
551377a0
...
@@ -30,6 +30,8 @@
...
@@ -30,6 +30,8 @@
#include <include/preprocess_op.h>
#include <include/preprocess_op.h>
#include <include/utility.h>
#include <include/utility.h>
using
namespace
paddle_infer
;
namespace
PaddleOCR
{
namespace
PaddleOCR
{
class
Classifier
{
class
Classifier
{
...
@@ -37,14 +39,12 @@ public:
...
@@ -37,14 +39,12 @@ 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
bool
&
use_zero_copy_run
,
const
bool
&
use_mkldnn
,
const
double
&
cls_thresh
)
{
const
double
&
cls_thresh
)
{
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_zero_copy_run_
=
use_zero_copy_run
;
this
->
cls_thresh
=
cls_thresh
;
this
->
cls_thresh
=
cls_thresh
;
...
@@ -57,14 +57,13 @@ public:
...
@@ -57,14 +57,13 @@ public:
cv
::
Mat
Run
(
cv
::
Mat
&
img
);
cv
::
Mat
Run
(
cv
::
Mat
&
img
);
private:
private:
std
::
shared_ptr
<
P
addleP
redictor
>
predictor_
;
std
::
shared_ptr
<
Predictor
>
predictor_
;
bool
use_gpu_
=
false
;
bool
use_gpu_
=
false
;
int
gpu_id_
=
0
;
int
gpu_id_
=
0
;
int
gpu_mem_
=
4000
;
int
gpu_mem_
=
4000
;
int
cpu_math_library_num_threads_
=
4
;
int
cpu_math_library_num_threads_
=
4
;
bool
use_mkldnn_
=
false
;
bool
use_mkldnn_
=
false
;
bool
use_zero_copy_run_
=
false
;
double
cls_thresh
=
0.5
;
double
cls_thresh
=
0.5
;
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
};
...
...
deploy/cpp_infer/include/ocr_det.h
浏览文件 @
551377a0
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
#include <include/postprocess_op.h>
#include <include/postprocess_op.h>
#include <include/preprocess_op.h>
#include <include/preprocess_op.h>
using
namespace
paddle_infer
;
namespace
PaddleOCR
{
namespace
PaddleOCR
{
class
DBDetector
{
class
DBDetector
{
...
@@ -39,8 +41,8 @@ public:
...
@@ -39,8 +41,8 @@ public:
explicit
DBDetector
(
const
std
::
string
&
model_dir
,
const
bool
&
use_gpu
,
explicit
DBDetector
(
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
bool
&
use_zero_copy_ru
n
,
const
bool
&
use_mkldnn
,
const
int
&
max_side_le
n
,
const
int
&
max_side_len
,
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
)
{
...
@@ -49,7 +51,6 @@ public:
...
@@ -49,7 +51,6 @@ public:
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_zero_copy_run_
=
use_zero_copy_run
;
this
->
max_side_len_
=
max_side_len
;
this
->
max_side_len_
=
max_side_len
;
...
@@ -69,14 +70,13 @@ public:
...
@@ -69,14 +70,13 @@ public:
void
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
);
void
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
&
boxes
);
private:
private:
std
::
shared_ptr
<
P
addleP
redictor
>
predictor_
;
std
::
shared_ptr
<
Predictor
>
predictor_
;
bool
use_gpu_
=
false
;
bool
use_gpu_
=
false
;
int
gpu_id_
=
0
;
int
gpu_id_
=
0
;
int
gpu_mem_
=
4000
;
int
gpu_mem_
=
4000
;
int
cpu_math_library_num_threads_
=
4
;
int
cpu_math_library_num_threads_
=
4
;
bool
use_mkldnn_
=
false
;
bool
use_mkldnn_
=
false
;
bool
use_zero_copy_run_
=
false
;
int
max_side_len_
=
960
;
int
max_side_len_
=
960
;
...
...
deploy/cpp_infer/include/ocr_rec.h
浏览文件 @
551377a0
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
#include <include/preprocess_op.h>
#include <include/preprocess_op.h>
#include <include/utility.h>
#include <include/utility.h>
using
namespace
paddle_infer
;
namespace
PaddleOCR
{
namespace
PaddleOCR
{
class
CRNNRecognizer
{
class
CRNNRecognizer
{
...
@@ -39,14 +41,12 @@ public:
...
@@ -39,14 +41,12 @@ 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
bool
&
use_zero_copy_run
,
const
bool
&
use_mkldnn
,
const
string
&
label_path
)
{
const
string
&
label_path
)
{
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_zero_copy_run_
=
use_zero_copy_run
;
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
(),
...
@@ -63,14 +63,13 @@ public:
...
@@ -63,14 +63,13 @@ public:
Classifier
*
cls
);
Classifier
*
cls
);
private:
private:
std
::
shared_ptr
<
P
addleP
redictor
>
predictor_
;
std
::
shared_ptr
<
Predictor
>
predictor_
;
bool
use_gpu_
=
false
;
bool
use_gpu_
=
false
;
int
gpu_id_
=
0
;
int
gpu_id_
=
0
;
int
gpu_mem_
=
4000
;
int
gpu_mem_
=
4000
;
int
cpu_math_library_num_threads_
=
4
;
int
cpu_math_library_num_threads_
=
4
;
bool
use_mkldnn_
=
false
;
bool
use_mkldnn_
=
false
;
bool
use_zero_copy_run_
=
false
;
std
::
vector
<
std
::
string
>
label_list_
;
std
::
vector
<
std
::
string
>
label_list_
;
...
...
deploy/cpp_infer/src/config.cpp
浏览文件 @
551377a0
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
namespace
PaddleOCR
{
namespace
PaddleOCR
{
std
::
vector
<
std
::
string
>
Config
::
split
(
const
std
::
string
&
str
,
std
::
vector
<
std
::
string
>
OCR
Config
::
split
(
const
std
::
string
&
str
,
const
std
::
string
&
delim
)
{
const
std
::
string
&
delim
)
{
std
::
vector
<
std
::
string
>
res
;
std
::
vector
<
std
::
string
>
res
;
if
(
""
==
str
)
if
(
""
==
str
)
return
res
;
return
res
;
...
@@ -38,7 +38,7 @@ std::vector<std::string> Config::split(const std::string &str,
...
@@ -38,7 +38,7 @@ std::vector<std::string> Config::split(const std::string &str,
}
}
std
::
map
<
std
::
string
,
std
::
string
>
std
::
map
<
std
::
string
,
std
::
string
>
Config
::
LoadConfig
(
const
std
::
string
&
config_path
)
{
OCR
Config
::
LoadConfig
(
const
std
::
string
&
config_path
)
{
auto
config
=
Utility
::
ReadDict
(
config_path
);
auto
config
=
Utility
::
ReadDict
(
config_path
);
std
::
map
<
std
::
string
,
std
::
string
>
dict
;
std
::
map
<
std
::
string
,
std
::
string
>
dict
;
...
@@ -53,7 +53,7 @@ Config::LoadConfig(const std::string &config_path) {
...
@@ -53,7 +53,7 @@ Config::LoadConfig(const std::string &config_path) {
return
dict
;
return
dict
;
}
}
void
Config
::
PrintConfigInfo
()
{
void
OCR
Config
::
PrintConfigInfo
()
{
std
::
cout
<<
"=======Paddle OCR inference config======"
<<
std
::
endl
;
std
::
cout
<<
"=======Paddle OCR inference config======"
<<
std
::
endl
;
for
(
auto
iter
=
config_map_
.
begin
();
iter
!=
config_map_
.
end
();
iter
++
)
{
for
(
auto
iter
=
config_map_
.
begin
();
iter
!=
config_map_
.
end
();
iter
++
)
{
std
::
cout
<<
iter
->
first
<<
" : "
<<
iter
->
second
<<
std
::
endl
;
std
::
cout
<<
iter
->
first
<<
" : "
<<
iter
->
second
<<
std
::
endl
;
...
...
deploy/cpp_infer/src/main.cpp
浏览文件 @
551377a0
...
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
...
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
exit
(
1
);
exit
(
1
);
}
}
Config
config
(
argv
[
1
]);
OCR
Config
config
(
argv
[
1
]);
config
.
PrintConfigInfo
();
config
.
PrintConfigInfo
();
...
@@ -50,24 +50,22 @@ int main(int argc, char **argv) {
...
@@ -50,24 +50,22 @@ int main(int argc, char **argv) {
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
DBDetector
det
(
DBDetector
det
(
config
.
det_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
det_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
cpu_math_library_num_threads
,
config
.
use_mkldnn
,
config
.
use_mkldnn
,
config
.
max_side_len
,
config
.
det_db_thresh
,
config
.
use_zero_copy_run
,
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
);
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
.
use_zero_copy_run
,
config
.
use_mkldnn
,
config
.
cls_thresh
);
config
.
cls_thresh
);
}
}
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
.
use_zero_copy_run
,
config
.
use_mkldnn
,
config
.
char_list_file
);
config
.
char_list_file
);
#ifdef USE_MKL
#ifdef USE_MKL
#pragma omp parallel
#pragma omp parallel
...
...
deploy/cpp_infer/src/ocr_cls.cpp
浏览文件 @
551377a0
...
@@ -35,26 +35,16 @@ cv::Mat Classifier::Run(cv::Mat &img) {
...
@@ -35,26 +35,16 @@ cv::Mat Classifier::Run(cv::Mat &img) {
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
// Inference.
// Inference.
if
(
this
->
use_zero_copy_run_
)
{
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
auto
input_t
=
this
->
predictor_
->
GetInputHandle
(
input_names
[
0
]);
auto
input_t
=
this
->
predictor_
->
GetInputTensor
(
input_names
[
0
]);
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
->
CopyFromCpu
(
input
.
data
());
input_t
->
copy_from_cpu
(
input
.
data
());
this
->
predictor_
->
Run
();
this
->
predictor_
->
ZeroCopyRun
();
}
else
{
paddle
::
PaddleTensor
input_t
;
input_t
.
shape
=
{
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
};
input_t
.
data
=
paddle
::
PaddleBuf
(
input
.
data
(),
input
.
size
()
*
sizeof
(
float
));
input_t
.
dtype
=
PaddleDType
::
FLOAT32
;
std
::
vector
<
paddle
::
PaddleTensor
>
outputs
;
this
->
predictor_
->
Run
({
input_t
},
&
outputs
,
1
);
}
std
::
vector
<
float
>
softmax_out
;
std
::
vector
<
float
>
softmax_out
;
std
::
vector
<
int64_t
>
label_out
;
std
::
vector
<
int64_t
>
label_out
;
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
softmax_out_t
=
this
->
predictor_
->
GetOutput
Tensor
(
output_names
[
0
]);
auto
softmax_out_t
=
this
->
predictor_
->
GetOutput
Handle
(
output_names
[
0
]);
auto
softmax_shape_out
=
softmax_out_t
->
shape
();
auto
softmax_shape_out
=
softmax_out_t
->
shape
();
int
softmax_out_num
=
int
softmax_out_num
=
...
@@ -63,7 +53,7 @@ cv::Mat Classifier::Run(cv::Mat &img) {
...
@@ -63,7 +53,7 @@ cv::Mat Classifier::Run(cv::Mat &img) {
softmax_out
.
resize
(
softmax_out_num
);
softmax_out
.
resize
(
softmax_out_num
);
softmax_out_t
->
copy_to_c
pu
(
softmax_out
.
data
());
softmax_out_t
->
CopyToC
pu
(
softmax_out
.
data
());
float
score
=
0
;
float
score
=
0
;
int
label
=
0
;
int
label
=
0
;
...
@@ -95,7 +85,7 @@ void Classifier::LoadModel(const std::string &model_dir) {
...
@@ -95,7 +85,7 @@ void Classifier::LoadModel(const std::string &model_dir) {
}
}
// false for zero copy tensor
// false for zero copy tensor
config
.
SwitchUseFeedFetchOps
(
!
this
->
use_zero_copy_run_
);
config
.
SwitchUseFeedFetchOps
(
false
);
// true for multiple input
// true for multiple input
config
.
SwitchSpecifyInputNames
(
true
);
config
.
SwitchSpecifyInputNames
(
true
);
...
@@ -104,6 +94,6 @@ void Classifier::LoadModel(const std::string &model_dir) {
...
@@ -104,6 +94,6 @@ void Classifier::LoadModel(const std::string &model_dir) {
config
.
EnableMemoryOptim
();
config
.
EnableMemoryOptim
();
config
.
DisableGlogInfo
();
config
.
DisableGlogInfo
();
this
->
predictor_
=
CreateP
addleP
redictor
(
config
);
this
->
predictor_
=
CreatePredictor
(
config
);
}
}
}
// namespace PaddleOCR
}
// namespace PaddleOCR
deploy/cpp_infer/src/ocr_det.cpp
浏览文件 @
551377a0
...
@@ -17,12 +17,17 @@
...
@@ -17,12 +17,17 @@
namespace
PaddleOCR
{
namespace
PaddleOCR
{
void
DBDetector
::
LoadModel
(
const
std
::
string
&
model_dir
)
{
void
DBDetector
::
LoadModel
(
const
std
::
string
&
model_dir
)
{
AnalysisConfig
config
;
// AnalysisConfig config;
paddle_infer
::
Config
config
;
config
.
SetModel
(
model_dir
+
"/inference.pdmodel"
,
config
.
SetModel
(
model_dir
+
"/inference.pdmodel"
,
model_dir
+
"/inference.pdiparams"
);
model_dir
+
"/inference.pdiparams"
);
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(
// 1 << 20, 1, 3,
// AnalysisConfig::Precision::kFloat32,
// false, false);
}
else
{
}
else
{
config
.
DisableGpu
();
config
.
DisableGpu
();
if
(
this
->
use_mkldnn_
)
{
if
(
this
->
use_mkldnn_
)
{
...
@@ -32,10 +37,8 @@ void DBDetector::LoadModel(const std::string &model_dir) {
...
@@ -32,10 +37,8 @@ void DBDetector::LoadModel(const std::string &model_dir) {
}
}
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
);
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
);
}
}
// use zero_copy_run as default
// false for zero copy tensor
config
.
SwitchUseFeedFetchOps
(
false
);
// true for commom tensor
config
.
SwitchUseFeedFetchOps
(
!
this
->
use_zero_copy_run_
);
// true for multiple input
// true for multiple input
config
.
SwitchSpecifyInputNames
(
true
);
config
.
SwitchSpecifyInputNames
(
true
);
...
@@ -44,7 +47,7 @@ void DBDetector::LoadModel(const std::string &model_dir) {
...
@@ -44,7 +47,7 @@ void DBDetector::LoadModel(const std::string &model_dir) {
config
.
EnableMemoryOptim
();
config
.
EnableMemoryOptim
();
config
.
DisableGlogInfo
();
config
.
DisableGlogInfo
();
this
->
predictor_
=
CreateP
addleP
redictor
(
config
);
this
->
predictor_
=
CreatePredictor
(
config
);
}
}
void
DBDetector
::
Run
(
cv
::
Mat
&
img
,
void
DBDetector
::
Run
(
cv
::
Mat
&
img
,
...
@@ -64,31 +67,21 @@ void DBDetector::Run(cv::Mat &img,
...
@@ -64,31 +67,21 @@ void DBDetector::Run(cv::Mat &img,
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
// Inference.
// Inference.
if
(
this
->
use_zero_copy_run_
)
{
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
auto
input_t
=
this
->
predictor_
->
GetInputHandle
(
input_names
[
0
]);
auto
input_t
=
this
->
predictor_
->
GetInputTensor
(
input_names
[
0
]);
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
->
CopyFromCpu
(
input
.
data
());
input_t
->
copy_from_cpu
(
input
.
data
());
this
->
predictor_
->
Run
();
this
->
predictor_
->
ZeroCopyRun
();
}
else
{
paddle
::
PaddleTensor
input_t
;
input_t
.
shape
=
{
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
};
input_t
.
data
=
paddle
::
PaddleBuf
(
input
.
data
(),
input
.
size
()
*
sizeof
(
float
));
input_t
.
dtype
=
PaddleDType
::
FLOAT32
;
std
::
vector
<
paddle
::
PaddleTensor
>
outputs
;
this
->
predictor_
->
Run
({
input_t
},
&
outputs
,
1
);
}
std
::
vector
<
float
>
out_data
;
std
::
vector
<
float
>
out_data
;
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_t
=
this
->
predictor_
->
GetOutput
Tensor
(
output_names
[
0
]);
auto
output_t
=
this
->
predictor_
->
GetOutput
Handle
(
output_names
[
0
]);
std
::
vector
<
int
>
output_shape
=
output_t
->
shape
();
std
::
vector
<
int
>
output_shape
=
output_t
->
shape
();
int
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
int
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
std
::
multiplies
<
int
>
());
out_data
.
resize
(
out_num
);
out_data
.
resize
(
out_num
);
output_t
->
copy_to_c
pu
(
out_data
.
data
());
output_t
->
CopyToC
pu
(
out_data
.
data
());
int
n2
=
output_shape
[
2
];
int
n2
=
output_shape
[
2
];
int
n3
=
output_shape
[
3
];
int
n3
=
output_shape
[
3
];
...
...
deploy/cpp_infer/src/ocr_rec.cpp
浏览文件 @
551377a0
...
@@ -43,32 +43,22 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -43,32 +43,22 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
// Inference.
// Inference.
if
(
this
->
use_zero_copy_run_
)
{
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
auto
input_t
=
this
->
predictor_
->
GetInputHandle
(
input_names
[
0
]);
auto
input_t
=
this
->
predictor_
->
GetInputTensor
(
input_names
[
0
]);
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
->
CopyFromCpu
(
input
.
data
());
input_t
->
copy_from_cpu
(
input
.
data
());
this
->
predictor_
->
Run
();
this
->
predictor_
->
ZeroCopyRun
();
}
else
{
paddle
::
PaddleTensor
input_t
;
input_t
.
shape
=
{
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
};
input_t
.
data
=
paddle
::
PaddleBuf
(
input
.
data
(),
input
.
size
()
*
sizeof
(
float
));
input_t
.
dtype
=
PaddleDType
::
FLOAT32
;
std
::
vector
<
paddle
::
PaddleTensor
>
outputs
;
this
->
predictor_
->
Run
({
input_t
},
&
outputs
,
1
);
}
std
::
vector
<
float
>
predict_batch
;
std
::
vector
<
float
>
predict_batch
;
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_t
=
this
->
predictor_
->
GetOutput
Tensor
(
output_names
[
0
]);
auto
output_t
=
this
->
predictor_
->
GetOutput
Handle
(
output_names
[
0
]);
auto
predict_shape
=
output_t
->
shape
();
auto
predict_shape
=
output_t
->
shape
();
int
out_num
=
std
::
accumulate
(
predict_shape
.
begin
(),
predict_shape
.
end
(),
1
,
int
out_num
=
std
::
accumulate
(
predict_shape
.
begin
(),
predict_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
std
::
multiplies
<
int
>
());
predict_batch
.
resize
(
out_num
);
predict_batch
.
resize
(
out_num
);
output_t
->
copy_to_c
pu
(
predict_batch
.
data
());
output_t
->
CopyToC
pu
(
predict_batch
.
data
());
// ctc decode
// ctc decode
std
::
vector
<
std
::
string
>
str_res
;
std
::
vector
<
std
::
string
>
str_res
;
...
@@ -102,7 +92,8 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -102,7 +92,8 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
}
}
void
CRNNRecognizer
::
LoadModel
(
const
std
::
string
&
model_dir
)
{
void
CRNNRecognizer
::
LoadModel
(
const
std
::
string
&
model_dir
)
{
AnalysisConfig
config
;
// AnalysisConfig config;
paddle_infer
::
Config
config
;
config
.
SetModel
(
model_dir
+
"/inference.pdmodel"
,
config
.
SetModel
(
model_dir
+
"/inference.pdmodel"
,
model_dir
+
"/inference.pdiparams"
);
model_dir
+
"/inference.pdiparams"
);
...
@@ -118,9 +109,7 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
...
@@ -118,9 +109,7 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
);
config
.
SetCpuMathLibraryNumThreads
(
this
->
cpu_math_library_num_threads_
);
}
}
// false for zero copy tensor
config
.
SwitchUseFeedFetchOps
(
false
);
// true for commom tensor
config
.
SwitchUseFeedFetchOps
(
!
this
->
use_zero_copy_run_
);
// true for multiple input
// true for multiple input
config
.
SwitchSpecifyInputNames
(
true
);
config
.
SwitchSpecifyInputNames
(
true
);
...
@@ -129,7 +118,7 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
...
@@ -129,7 +118,7 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
config
.
EnableMemoryOptim
();
config
.
EnableMemoryOptim
();
config
.
DisableGlogInfo
();
config
.
DisableGlogInfo
();
this
->
predictor_
=
CreateP
addleP
redictor
(
config
);
this
->
predictor_
=
CreatePredictor
(
config
);
}
}
cv
::
Mat
CRNNRecognizer
::
GetRotateCropImage
(
const
cv
::
Mat
&
srcimage
,
cv
::
Mat
CRNNRecognizer
::
GetRotateCropImage
(
const
cv
::
Mat
&
srcimage
,
...
...
deploy/cpp_infer/tools/config.txt
浏览文件 @
551377a0
# model load config
# model load config
use_gpu
0
use_gpu 0
gpu_id 0
gpu_id 0
gpu_mem 4000
gpu_mem 4000
cpu_math_library_num_threads 10
cpu_math_library_num_threads 10
use_mkldnn 0
use_mkldnn 0
use_zero_copy_run 1
# det config
# det config
max_side_len 960
max_side_len 960
det_db_thresh 0.3
det_db_thresh 0.3
det_db_box_thresh 0.5
det_db_box_thresh 0.5
det_db_unclip_ratio 2.0
det_db_unclip_ratio 2.0
det_model_dir .
/inference/ch_
_ppocr_mobile_v2.0_det_infer/
det_model_dir .
./../../deploy/cpp_infer/inference/ch
_ppocr_mobile_v2.0_det_infer/
# cls config
# cls config
use_angle_cls 0
use_angle_cls 0
...
@@ -19,7 +18,7 @@ cls_model_dir ./inference/ch_ppocr_mobile_v2.0_cls_infer/
...
@@ -19,7 +18,7 @@ cls_model_dir ./inference/ch_ppocr_mobile_v2.0_cls_infer/
cls_thresh 0.9
cls_thresh 0.9
# rec config
# rec config
rec_model_dir ./inference/ch_ppocr_mobile_v2.0_rec_infer/
rec_model_dir .
./../../deploy/cpp_infer
/inference/ch_ppocr_mobile_v2.0_rec_infer/
char_list_file ../../ppocr/utils/ppocr_keys_v1.txt
char_list_file ../../ppocr/utils/ppocr_keys_v1.txt
# show the detection results
# show the detection results
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录