Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
18aed01d
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
18aed01d
编写于
8月 25, 2021
作者:
qq_25193841
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/dygraph' into dygraph
上级
1814a53f
45dff759
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
247 addition
and
50 deletion
+247
-50
deploy/cpp_infer/CMakeLists.txt
deploy/cpp_infer/CMakeLists.txt
+4
-0
deploy/cpp_infer/external-cmake/auto-log.cmake
deploy/cpp_infer/external-cmake/auto-log.cmake
+14
-0
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+24
-45
ppocr/losses/cls_loss.py
ppocr/losses/cls_loss.py
+1
-1
tests/ocr_det_params.txt
tests/ocr_det_params.txt
+15
-0
tests/prepare.sh
tests/prepare.sh
+71
-2
tests/test.sh
tests/test.sh
+112
-1
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+1
-1
tools/infer/utility.py
tools/infer/utility.py
+5
-0
未找到文件。
deploy/cpp_infer/CMakeLists.txt
浏览文件 @
18aed01d
...
...
@@ -206,6 +206,10 @@ endif()
set
(
DEPS
${
DEPS
}
${
OpenCV_LIBS
}
)
include
(
ExternalProject
)
include
(
external-cmake/auto-log.cmake
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
/autolog/src/extern_Autolog/auto_log
)
AUX_SOURCE_DIRECTORY
(
./src SRCS
)
add_executable
(
${
DEMO_NAME
}
${
SRCS
}
)
...
...
deploy/cpp_infer/external-cmake/auto-log.cmake
0 → 100644
浏览文件 @
18aed01d
find_package
(
Git REQUIRED
)
message
(
"
${
CMAKE_BUILD_TYPE
}
"
)
set
(
AUTOLOG_REPOSITORY https://github.com/LDOUBLEV/AutoLog.git
)
SET
(
AUTOLOG_INSTALL_DIR
${
CMAKE_CURRENT_BINARY_DIR
}
/install/Autolog
)
ExternalProject_Add
(
extern_Autolog
PREFIX autolog
GIT_REPOSITORY
${
AUTOLOG_REPOSITORY
}
GIT_TAG main
DOWNLOAD_NO_EXTRACT True
INSTALL_COMMAND cmake -E echo
"Skipping install step."
)
deploy/cpp_infer/src/main.cpp
浏览文件 @
18aed01d
...
...
@@ -39,8 +39,8 @@
DEFINE_bool
(
use_gpu
,
false
,
"Infering with GPU or CPU."
);
DEFINE_int32
(
gpu_id
,
0
,
"Device id of GPU to execute."
);
DEFINE_int32
(
gpu_mem
,
4000
,
"GPU id when infering with GPU."
);
DEFINE_int32
(
cpu_
math_library_num_
threads
,
10
,
"Num of threads with CPU."
);
DEFINE_bool
(
us
e_mkldnn
,
false
,
"Whether use mkldnn with CPU."
);
DEFINE_int32
(
cpu_threads
,
10
,
"Num of threads with CPU."
);
DEFINE_bool
(
enabl
e_mkldnn
,
false
,
"Whether use mkldnn with CPU."
);
DEFINE_bool
(
use_tensorrt
,
false
,
"Whether use tensorrt."
);
DEFINE_string
(
precision
,
"fp32"
,
"Precision be one of fp32/fp16/int8"
);
DEFINE_bool
(
benchmark
,
true
,
"Whether use benchmark."
);
...
...
@@ -60,6 +60,7 @@ DEFINE_string(cls_model_dir, "", "Path of cls inference model.");
DEFINE_double
(
cls_thresh
,
0.9
,
"Threshold of cls_thresh."
);
// recognition related
DEFINE_string
(
rec_model_dir
,
""
,
"Path of rec inference model."
);
DEFINE_int32
(
rec_batch_num
,
1
,
"rec_batch_num."
);
DEFINE_string
(
char_list_file
,
"../../ppocr/utils/ppocr_keys_v1.txt"
,
"Path of dictionary."
);
...
...
@@ -68,34 +69,6 @@ using namespace cv;
using
namespace
PaddleOCR
;
void
PrintBenchmarkLog
(
std
::
string
model_name
,
int
batch_size
,
std
::
string
input_shape
,
std
::
vector
<
double
>
time_info
,
int
img_num
){
LOG
(
INFO
)
<<
"----------------------- Config info -----------------------"
;
LOG
(
INFO
)
<<
"runtime_device: "
<<
(
FLAGS_use_gpu
?
"gpu"
:
"cpu"
);
LOG
(
INFO
)
<<
"ir_optim: "
<<
"True"
;
LOG
(
INFO
)
<<
"enable_memory_optim: "
<<
"True"
;
LOG
(
INFO
)
<<
"enable_tensorrt: "
<<
FLAGS_use_tensorrt
;
LOG
(
INFO
)
<<
"enable_mkldnn: "
<<
(
FLAGS_use_mkldnn
?
"True"
:
"False"
);
LOG
(
INFO
)
<<
"cpu_math_library_num_threads: "
<<
FLAGS_cpu_math_library_num_threads
;
LOG
(
INFO
)
<<
"----------------------- Data info -----------------------"
;
LOG
(
INFO
)
<<
"batch_size: "
<<
batch_size
;
LOG
(
INFO
)
<<
"input_shape: "
<<
input_shape
;
LOG
(
INFO
)
<<
"data_num: "
<<
img_num
;
LOG
(
INFO
)
<<
"----------------------- Model info -----------------------"
;
LOG
(
INFO
)
<<
"model_name: "
<<
model_name
;
LOG
(
INFO
)
<<
"precision: "
<<
FLAGS_precision
;
LOG
(
INFO
)
<<
"----------------------- Perf info ------------------------"
;
LOG
(
INFO
)
<<
"Total time spent(ms): "
<<
std
::
accumulate
(
time_info
.
begin
(),
time_info
.
end
(),
0
);
LOG
(
INFO
)
<<
"preprocess_time(ms): "
<<
time_info
[
0
]
/
img_num
<<
", inference_time(ms): "
<<
time_info
[
1
]
/
img_num
<<
", postprocess_time(ms): "
<<
time_info
[
2
]
/
img_num
;
}
static
bool
PathExists
(
const
std
::
string
&
path
){
#ifdef _WIN32
struct
_stat
buffer
;
...
...
@@ -110,8 +83,8 @@ static bool PathExists(const std::string& path){
int
main_det
(
std
::
vector
<
cv
::
String
>
cv_all_img_names
)
{
std
::
vector
<
double
>
time_info
=
{
0
,
0
,
0
};
DBDetector
det
(
FLAGS_det_model_dir
,
FLAGS_use_gpu
,
FLAGS_gpu_id
,
FLAGS_gpu_mem
,
FLAGS_cpu_
math_library_num_
threads
,
FLAGS_
us
e_mkldnn
,
FLAGS_max_side_len
,
FLAGS_det_db_thresh
,
FLAGS_gpu_mem
,
FLAGS_cpu_threads
,
FLAGS_
enabl
e_mkldnn
,
FLAGS_max_side_len
,
FLAGS_det_db_thresh
,
FLAGS_det_db_box_thresh
,
FLAGS_det_db_unclip_ratio
,
FLAGS_use_polygon_score
,
FLAGS_visualize
,
FLAGS_use_tensorrt
,
FLAGS_precision
);
...
...
@@ -135,7 +108,17 @@ int main_det(std::vector<cv::String> cv_all_img_names) {
}
if
(
FLAGS_benchmark
)
{
PrintBenchmarkLog
(
"det"
,
1
,
"dynamic"
,
time_info
,
cv_all_img_names
.
size
());
AutoLogger
autolog
(
"ocr_det"
,
FLAGS_use_gpu
,
FLAGS_use_tensorrt
,
FLAGS_enable_mkldnn
,
FLAGS_cpu_threads
,
1
,
"dynamic"
,
FLAGS_precision
,
time_info
,
cv_all_img_names
.
size
());
autolog
.
report
();
}
return
0
;
}
...
...
@@ -144,8 +127,8 @@ int main_det(std::vector<cv::String> cv_all_img_names) {
int
main_rec
(
std
::
vector
<
cv
::
String
>
cv_all_img_names
)
{
std
::
vector
<
double
>
time_info
=
{
0
,
0
,
0
};
CRNNRecognizer
rec
(
FLAGS_rec_model_dir
,
FLAGS_use_gpu
,
FLAGS_gpu_id
,
FLAGS_gpu_mem
,
FLAGS_cpu_
math_library_num_
threads
,
FLAGS_
us
e_mkldnn
,
FLAGS_char_list_file
,
FLAGS_gpu_mem
,
FLAGS_cpu_threads
,
FLAGS_
enabl
e_mkldnn
,
FLAGS_char_list_file
,
FLAGS_use_tensorrt
,
FLAGS_precision
);
for
(
int
i
=
0
;
i
<
cv_all_img_names
.
size
();
++
i
)
{
...
...
@@ -165,18 +148,14 @@ int main_rec(std::vector<cv::String> cv_all_img_names) {
time_info
[
2
]
+=
rec_times
[
2
];
}
if
(
FLAGS_benchmark
)
{
PrintBenchmarkLog
(
"rec"
,
1
,
"dynamic"
,
time_info
,
cv_all_img_names
.
size
());
}
return
0
;
}
int
main_system
(
std
::
vector
<
cv
::
String
>
cv_all_img_names
)
{
DBDetector
det
(
FLAGS_det_model_dir
,
FLAGS_use_gpu
,
FLAGS_gpu_id
,
FLAGS_gpu_mem
,
FLAGS_cpu_
math_library_num_
threads
,
FLAGS_
us
e_mkldnn
,
FLAGS_max_side_len
,
FLAGS_det_db_thresh
,
FLAGS_gpu_mem
,
FLAGS_cpu_threads
,
FLAGS_
enabl
e_mkldnn
,
FLAGS_max_side_len
,
FLAGS_det_db_thresh
,
FLAGS_det_db_box_thresh
,
FLAGS_det_db_unclip_ratio
,
FLAGS_use_polygon_score
,
FLAGS_visualize
,
FLAGS_use_tensorrt
,
FLAGS_precision
);
...
...
@@ -184,14 +163,14 @@ int main_system(std::vector<cv::String> cv_all_img_names) {
Classifier
*
cls
=
nullptr
;
if
(
FLAGS_use_angle_cls
)
{
cls
=
new
Classifier
(
FLAGS_cls_model_dir
,
FLAGS_use_gpu
,
FLAGS_gpu_id
,
FLAGS_gpu_mem
,
FLAGS_cpu_
math_library_num_
threads
,
FLAGS_
us
e_mkldnn
,
FLAGS_cls_thresh
,
FLAGS_gpu_mem
,
FLAGS_cpu_threads
,
FLAGS_
enabl
e_mkldnn
,
FLAGS_cls_thresh
,
FLAGS_use_tensorrt
,
FLAGS_precision
);
}
CRNNRecognizer
rec
(
FLAGS_rec_model_dir
,
FLAGS_use_gpu
,
FLAGS_gpu_id
,
FLAGS_gpu_mem
,
FLAGS_cpu_
math_library_num_
threads
,
FLAGS_
us
e_mkldnn
,
FLAGS_char_list_file
,
FLAGS_gpu_mem
,
FLAGS_cpu_threads
,
FLAGS_
enabl
e_mkldnn
,
FLAGS_char_list_file
,
FLAGS_use_tensorrt
,
FLAGS_precision
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
...
...
ppocr/losses/cls_loss.py
浏览文件 @
18aed01d
...
...
@@ -25,6 +25,6 @@ class ClsLoss(nn.Layer):
self
.
loss_func
=
nn
.
CrossEntropyLoss
(
reduction
=
'mean'
)
def
forward
(
self
,
predicts
,
batch
):
label
=
batch
[
1
]
label
=
batch
[
1
]
.
astype
(
"int64"
)
loss
=
self
.
loss_func
(
input
=
predicts
,
label
=
label
)
return
{
'loss'
:
loss
}
tests/ocr_det_params.txt
浏览文件 @
18aed01d
...
...
@@ -49,4 +49,19 @@ inference:tools/infer/predict_det.py
--save_log_path:null
--benchmark:True
null:null
===========================cpp_infer_params===========================
use_opencv:True
infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/
infer_quant:False
inference:./deploy/cpp_infer/build/ppocr det
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1
--use_tensorrt:False|True
--precision:fp32|fp16
--det_model_dir:
--image_dir:./inference/ch_det_data_50/all-sum-510/
--save_log_path:null
--benchmark:True
tests/prepare.sh
浏览文件 @
18aed01d
#!/bin/bash
FILENAME
=
$1
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer']
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer'
, 'cpp_infer'
]
MODE
=
$2
dataline
=
$(
cat
${
FILENAME
}
)
...
...
@@ -58,7 +58,7 @@ elif [ ${MODE} = "whole_infer" ];then
cd
./train_data/
&&
tar
xf icdar2015_infer.tar
&&
tar
xf ic15_data.tar
ln
-s
./icdar2015_infer ./icdar2015
cd
../
el
se
el
if
[
${
MODE
}
=
"infer"
]
||
[
${
MODE
}
=
"cpp_infer"
]
;
then
if
[
${
model_name
}
=
"ocr_det"
]
;
then
eval_model_name
=
"ch_ppocr_mobile_v2.0_det_infer"
rm
-rf
./train_data/icdar2015
...
...
@@ -74,3 +74,72 @@ else
fi
fi
if
[
${
MODE
}
=
"cpp_infer"
]
;
then
cd
deploy/cpp_infer
use_opencv
=
$(
func_parser_value
"
${
lines
[52]
}
"
)
if
[
${
use_opencv
}
=
"True"
]
;
then
echo
"################### build opencv ###################"
rm
-rf
3.4.7.tar.gz opencv-3.4.7/
wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz
tar
-xf
3.4.7.tar.gz
cd
opencv-3.4.7/
install_path
=
$(
pwd
)
/opencv-3.4.7/opencv3
rm
-rf
build
mkdir
build
cd
build
cmake ..
\
-DCMAKE_INSTALL_PREFIX
=
${
install_path
}
\
-DCMAKE_BUILD_TYPE
=
Release
\
-DBUILD_SHARED_LIBS
=
OFF
\
-DWITH_IPP
=
OFF
\
-DBUILD_IPP_IW
=
OFF
\
-DWITH_LAPACK
=
OFF
\
-DWITH_EIGEN
=
OFF
\
-DCMAKE_INSTALL_LIBDIR
=
lib64
\
-DWITH_ZLIB
=
ON
\
-DBUILD_ZLIB
=
ON
\
-DWITH_JPEG
=
ON
\
-DBUILD_JPEG
=
ON
\
-DWITH_PNG
=
ON
\
-DBUILD_PNG
=
ON
\
-DWITH_TIFF
=
ON
\
-DBUILD_TIFF
=
ON
make
-j
make
install
cd
../
echo
"################### build opencv finished ###################"
fi
echo
"################### build PaddleOCR demo ####################"
if
[
${
use_opencv
}
=
"True"
]
;
then
OPENCV_DIR
=
$(
pwd
)
/opencv-3.4.7/opencv3/
else
OPENCV_DIR
=
''
fi
LIB_DIR
=
$(
pwd
)
/Paddle/build/paddle_inference_install_dir/
CUDA_LIB_DIR
=
$(
dirname
`
find /usr
-name
libcudart.so
`
)
CUDNN_LIB_DIR
=
$(
dirname
`
find /usr
-name
libcudnn.so
`
)
BUILD_DIR
=
build
rm
-rf
${
BUILD_DIR
}
mkdir
${
BUILD_DIR
}
cd
${
BUILD_DIR
}
cmake ..
\
-DPADDLE_LIB
=
${
LIB_DIR
}
\
-DWITH_MKL
=
ON
\
-DWITH_GPU
=
OFF
\
-DWITH_STATIC_LIB
=
OFF
\
-DWITH_TENSORRT
=
OFF
\
-DOPENCV_DIR
=
${
OPENCV_DIR
}
\
-DCUDNN_LIB
=
${
CUDNN_LIB_DIR
}
\
-DCUDA_LIB
=
${
CUDA_LIB_DIR
}
\
-DTENSORRT_DIR
=
${
TENSORRT_DIR
}
\
make
-j
echo
"################### build PaddleOCR demo finished ###################"
fi
\ No newline at end of file
tests/test.sh
浏览文件 @
18aed01d
#!/bin/bash
FILENAME
=
$1
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer']
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer'
, 'cpp_infer'
]
MODE
=
$2
dataline
=
$(
cat
${
FILENAME
}
)
...
...
@@ -145,6 +145,33 @@ benchmark_value=$(func_parser_value "${lines[49]}")
infer_key1
=
$(
func_parser_key
"
${
lines
[50]
}
"
)
infer_value1
=
$(
func_parser_value
"
${
lines
[50]
}
"
)
if
[
${
MODE
}
=
"cpp_infer"
]
;
then
# parser cpp inference model
cpp_infer_model_dir_list
=
$(
func_parser_value
"
${
lines
[53]
}
"
)
cpp_infer_is_quant
=
$(
func_parser_value
"
${
lines
[54]
}
"
)
# parser cpp inference
inference_cmd
=
$(
func_parser_value
"
${
lines
[55]
}
"
)
cpp_use_gpu_key
=
$(
func_parser_key
"
${
lines
[56]
}
"
)
cpp_use_gpu_list
=
$(
func_parser_value
"
${
lines
[56]
}
"
)
cpp_use_mkldnn_key
=
$(
func_parser_key
"
${
lines
[57]
}
"
)
cpp_use_mkldnn_list
=
$(
func_parser_value
"
${
lines
[57]
}
"
)
cpp_cpu_threads_key
=
$(
func_parser_key
"
${
lines
[58]
}
"
)
cpp_cpu_threads_list
=
$(
func_parser_value
"
${
lines
[58]
}
"
)
cpp_batch_size_key
=
$(
func_parser_key
"
${
lines
[59]
}
"
)
cpp_batch_size_list
=
$(
func_parser_value
"
${
lines
[59]
}
"
)
cpp_use_trt_key
=
$(
func_parser_key
"
${
lines
[60]
}
"
)
cpp_use_trt_list
=
$(
func_parser_value
"
${
lines
[60]
}
"
)
cpp_precision_key
=
$(
func_parser_key
"
${
lines
[61]
}
"
)
cpp_precision_list
=
$(
func_parser_value
"
${
lines
[61]
}
"
)
cpp_infer_model_key
=
$(
func_parser_key
"
${
lines
[62]
}
"
)
cpp_image_dir_key
=
$(
func_parser_key
"
${
lines
[63]
}
"
)
cpp_infer_img_dir
=
$(
func_parser_value
"
${
lines
[63]
}
"
)
cpp_save_log_key
=
$(
func_parser_key
"
${
lines
[64]
}
"
)
cpp_benchmark_key
=
$(
func_parser_key
"
${
lines
[65]
}
"
)
cpp_benchmark_value
=
$(
func_parser_value
"
${
lines
[65]
}
"
)
fi
LOG_PATH
=
"./tests/output"
mkdir
-p
${
LOG_PATH
}
status_log
=
"
${
LOG_PATH
}
/results.log"
...
...
@@ -218,6 +245,71 @@ function func_inference(){
done
}
function
func_cpp_inference
(){
IFS
=
'|'
_script
=
$1
_model_dir
=
$2
_log_path
=
$3
_img_dir
=
$4
_flag_quant
=
$5
# inference
for
use_gpu
in
${
cpp_use_gpu_list
[*]
}
;
do
if
[
${
use_gpu
}
=
"False"
]
||
[
${
use_gpu
}
=
"cpu"
]
;
then
for
use_mkldnn
in
${
cpp_use_mkldnn_list
[*]
}
;
do
if
[
${
use_mkldnn
}
=
"False"
]
&&
[
${
_flag_quant
}
=
"True"
]
;
then
continue
fi
for
threads
in
${
cpp_cpu_threads_list
[*]
}
;
do
for
batch_size
in
${
cpp_batch_size_list
[*]
}
;
do
_save_log_path
=
"
${
_log_path
}
/cpp_infer_cpu_usemkldnn_
${
use_mkldnn
}
_threads_
${
threads
}
_batchsize_
${
batch_size
}
.log"
set_infer_data
=
$(
func_set_params
"
${
cpp_image_dir_key
}
"
"
${
_img_dir
}
"
)
set_benchmark
=
$(
func_set_params
"
${
cpp_benchmark_key
}
"
"
${
cpp_benchmark_value
}
"
)
set_batchsize
=
$(
func_set_params
"
${
cpp_batch_size_key
}
"
"
${
batch_size
}
"
)
set_cpu_threads
=
$(
func_set_params
"
${
cpp_cpu_threads_key
}
"
"
${
threads
}
"
)
set_model_dir
=
$(
func_set_params
"
${
cpp_infer_model_key
}
"
"
${
_model_dir
}
"
)
command
=
"
${
_script
}
${
cpp_use_gpu_key
}
=
${
use_gpu
}
${
cpp_use_mkldnn_key
}
=
${
use_mkldnn
}
${
set_cpu_threads
}
${
set_model_dir
}
${
set_batchsize
}
${
set_infer_data
}
${
set_benchmark
}
>
${
_save_log_path
}
2>&1 "
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
$last_status
"
${
command
}
"
"
${
status_log
}
"
done
done
done
elif
[
${
use_gpu
}
=
"True"
]
||
[
${
use_gpu
}
=
"gpu"
]
;
then
for
use_trt
in
${
cpp_use_trt_list
[*]
}
;
do
for
precision
in
${
cpp_precision_list
[*]
}
;
do
if
[[
${
_flag_quant
}
=
"False"
]]
&&
[[
${
precision
}
=
~
"int8"
]]
;
then
continue
fi
if
[[
${
precision
}
=
~
"fp16"
||
${
precision
}
=
~
"int8"
]]
&&
[
${
use_trt
}
=
"False"
]
;
then
continue
fi
if
[[
${
use_trt
}
=
"False"
||
${
precision
}
=
~
"int8"
]]
&&
[
${
_flag_quant
}
=
"True"
]
;
then
continue
fi
for
batch_size
in
${
cpp_batch_size_list
[*]
}
;
do
_save_log_path
=
"
${
_log_path
}
/cpp_infer_gpu_usetrt_
${
use_trt
}
_precision_
${
precision
}
_batchsize_
${
batch_size
}
.log"
set_infer_data
=
$(
func_set_params
"
${
cpp_image_dir_key
}
"
"
${
_img_dir
}
"
)
set_benchmark
=
$(
func_set_params
"
${
cpp_benchmark_key
}
"
"
${
cpp_benchmark_value
}
"
)
set_batchsize
=
$(
func_set_params
"
${
cpp_batch_size_key
}
"
"
${
batch_size
}
"
)
set_tensorrt
=
$(
func_set_params
"
${
cpp_use_trt_key
}
"
"
${
use_trt
}
"
)
set_precision
=
$(
func_set_params
"
${
cpp_precision_key
}
"
"
${
precision
}
"
)
set_model_dir
=
$(
func_set_params
"
${
cpp_infer_model_key
}
"
"
${
_model_dir
}
"
)
command
=
"
${
_script
}
${
cpp_use_gpu_key
}
=
${
use_gpu
}
${
set_tensorrt
}
${
set_precision
}
${
set_model_dir
}
${
set_batchsize
}
${
set_infer_data
}
${
set_benchmark
}
>
${
_save_log_path
}
2>&1 "
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
$last_status
"
${
command
}
"
"
${
status_log
}
"
done
done
done
else
echo
"Does not support hardware other than CPU and GPU Currently!"
fi
done
}
if
[
${
MODE
}
=
"infer"
]
;
then
GPUID
=
$3
if
[
${#
GPUID
}
-le
0
]
;
then
...
...
@@ -252,6 +344,25 @@ if [ ${MODE} = "infer" ]; then
Count
=
$((
$Count
+
1
))
done
elif
[
${
MODE
}
=
"cpp_infer"
]
;
then
GPUID
=
$3
if
[
${#
GPUID
}
-le
0
]
;
then
env
=
" "
else
env
=
"export CUDA_VISIBLE_DEVICES=
${
GPUID
}
"
fi
# set CUDA_VISIBLE_DEVICES
eval
$env
export
Count
=
0
IFS
=
"|"
infer_quant_flag
=(
${
cpp_infer_is_quant
}
)
for
infer_model
in
${
cpp_infer_model_dir_list
[*]
}
;
do
#run inference
is_quant
=
${
infer_quant_flag
[Count]
}
func_cpp_inference
"
${
inference_cmd
}
"
"
${
infer_model
}
"
"
${
LOG_PATH
}
"
"
${
cpp_infer_img_dir
}
"
${
is_quant
}
Count
=
$((
$Count
+
1
))
done
else
IFS
=
"|"
export
Count
=
0
...
...
tools/infer/predict_rec.py
浏览文件 @
18aed01d
...
...
@@ -278,7 +278,7 @@ def main(args):
if
args
.
warmup
:
img
=
np
.
random
.
uniform
(
0
,
255
,
[
32
,
320
,
3
]).
astype
(
np
.
uint8
)
for
i
in
range
(
2
):
res
=
text_recognizer
([
img
])
res
=
text_recognizer
([
img
]
*
int
(
args
.
rec_batch_num
)
)
for
image_file
in
image_file_list
:
img
,
flag
=
check_and_read_gif
(
image_file
)
...
...
tools/infer/utility.py
浏览文件 @
18aed01d
...
...
@@ -159,6 +159,11 @@ def create_predictor(args, mode, logger):
precision
=
inference
.
PrecisionType
.
Float32
if
args
.
use_gpu
:
gpu_id
=
get_infer_gpuid
()
if
gpu_id
is
None
:
raise
ValueError
(
"Not found GPU in current device. Please check your device or set args.use_gpu as False"
)
config
.
enable_use_gpu
(
args
.
gpu_mem
,
0
)
if
args
.
use_tensorrt
:
config
.
enable_tensorrt_engine
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录