Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
ac98415b
Commit
ac98415b
authored
Sep 14, 2021
by
WenmuZhou
Browse files
merge dygraph
parents
af34d785
29929ac6
Changes
69
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
195 additions
and
53 deletions
+195
-53
tests/readme.md
tests/readme.md
+28
-18
tests/results/det_results_gpu_fp32.txt
tests/results/det_results_gpu_fp32.txt
+20
-20
tests/test.sh
tests/test.sh
+122
-6
tools/eval.py
tools/eval.py
+2
-1
tools/infer/predict_e2e.py
tools/infer/predict_e2e.py
+1
-0
tools/infer/predict_system.py
tools/infer/predict_system.py
+3
-0
tools/infer/utility.py
tools/infer/utility.py
+2
-2
tools/infer_rec.py
tools/infer_rec.py
+9
-0
tools/program.py
tools/program.py
+8
-6
No files found.
tests/readme.md
View file @
ac98415b
...
...
@@ -25,34 +25,44 @@ test.sh和params.txt文件配合使用,完成OCR轻量检测和识别模型从
tests/
├── ocr_det_params.txt
# 测试OCR检测模型的参数配置文件
├── ocr_rec_params.txt
# 测试OCR识别模型的参数配置文件
├── ocr_ppocr_mobile_params.txt
# 测试OCR检测+识别模型串联的参数配置文件
└── prepare.sh
# 完成test.sh运行所需要的数据和模型下载
└── test.sh
# 根据
└── test.sh
# 测试主程序
```
# 使用方法
test.sh包含四种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是:
-
模式1 lite_train_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度;
```
-
模式1:lite_train_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度;
```
shell
bash
test
/prepare.sh ./tests/ocr_det_params.txt
'lite_train_infer'
bash tests/test.sh ./tests/ocr_det_params.txt
'lite_train_infer'
```
-
模式2 whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理;
```
-
模式2:whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理;
```
shell
bash tests/prepare.sh ./tests/ocr_det_params.txt
'whole_infer'
bash tests/test.sh ./tests/ocr_det_params.txt
'whole_infer'
```
-
模式3
infer 不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度;
```
-
模式3
:
infer 不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度;
```
shell
bash tests/prepare.sh ./tests/ocr_det_params.txt
'infer'
用法1:
#
用法1:
bash tests/test.sh ./tests/ocr_det_params.txt
'infer'
用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
#
用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
bash tests/test.sh ./tests/ocr_det_params.txt
'infer'
'1'
```
模式4
:
whole_train_infer , CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度
```
-
模式4
:
whole_train_infer , CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度
;
```
shell
bash tests/prepare.sh ./tests/ocr_det_params.txt
'whole_train_infer'
bash tests/test.sh ./tests/ocr_det_params.txt
'whole_train_infer'
```
-
模式5:cpp_infer , CE: 验证inference model的c++预测是否走通;
```
shell
bash tests/prepare.sh ./tests/ocr_det_params.txt
'cpp_infer'
bash tests/test.sh ./tests/ocr_det_params.txt
'cpp_infer'
```
tests/results/det_results_gpu_fp32.txt
View file @
ac98415b
This diff is collapsed.
Click to expand it.
tests/test.sh
View file @
ac98415b
...
...
@@ -144,6 +144,32 @@ benchmark_key=$(func_parser_key "${lines[49]}")
benchmark_value
=
$(
func_parser_value
"
${
lines
[49]
}
"
)
infer_key1
=
$(
func_parser_key
"
${
lines
[50]
}
"
)
infer_value1
=
$(
func_parser_value
"
${
lines
[50]
}
"
)
# parser serving
trans_model_py
=
$(
func_parser_value
"
${
lines
[67]
}
"
)
infer_model_dir_key
=
$(
func_parser_key
"
${
lines
[68]
}
"
)
infer_model_dir_value
=
$(
func_parser_value
"
${
lines
[68]
}
"
)
model_filename_key
=
$(
func_parser_key
"
${
lines
[69]
}
"
)
model_filename_value
=
$(
func_parser_value
"
${
lines
[69]
}
"
)
params_filename_key
=
$(
func_parser_key
"
${
lines
[70]
}
"
)
params_filename_value
=
$(
func_parser_value
"
${
lines
[70]
}
"
)
serving_server_key
=
$(
func_parser_key
"
${
lines
[71]
}
"
)
serving_server_value
=
$(
func_parser_value
"
${
lines
[71]
}
"
)
serving_client_key
=
$(
func_parser_key
"
${
lines
[72]
}
"
)
serving_client_value
=
$(
func_parser_value
"
${
lines
[72]
}
"
)
serving_dir_value
=
$(
func_parser_value
"
${
lines
[73]
}
"
)
web_service_py
=
$(
func_parser_value
"
${
lines
[74]
}
"
)
web_use_gpu_key
=
$(
func_parser_key
"
${
lines
[75]
}
"
)
web_use_gpu_list
=
$(
func_parser_value
"
${
lines
[75]
}
"
)
web_use_mkldnn_key
=
$(
func_parser_key
"
${
lines
[76]
}
"
)
web_use_mkldnn_list
=
$(
func_parser_value
"
${
lines
[76]
}
"
)
web_cpu_threads_key
=
$(
func_parser_key
"
${
lines
[77]
}
"
)
web_cpu_threads_list
=
$(
func_parser_value
"
${
lines
[77]
}
"
)
web_use_trt_key
=
$(
func_parser_key
"
${
lines
[78]
}
"
)
web_use_trt_list
=
$(
func_parser_value
"
${
lines
[78]
}
"
)
web_precision_key
=
$(
func_parser_key
"
${
lines
[79]
}
"
)
web_precision_list
=
$(
func_parser_value
"
${
lines
[79]
}
"
)
pipeline_py
=
$(
func_parser_value
"
${
lines
[80]
}
"
)
if
[
${
MODE
}
=
"cpp_infer"
]
;
then
# parser cpp inference model
...
...
@@ -166,7 +192,8 @@ if [ ${MODE} = "cpp_infer" ]; then
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_infer_key1
=
$(
func_parser_key
"
${
lines
[64]
}
"
)
cpp_infer_value1
=
$(
func_parser_value
"
${
lines
[64]
}
"
)
cpp_benchmark_key
=
$(
func_parser_key
"
${
lines
[65]
}
"
)
cpp_benchmark_value
=
$(
func_parser_value
"
${
lines
[65]
}
"
)
fi
...
...
@@ -244,6 +271,81 @@ function func_inference(){
fi
done
}
function
func_serving
(){
IFS
=
'|'
_python
=
$1
_script
=
$2
_model_dir
=
$3
# pdserving
set_dirname
=
$(
func_set_params
"
${
infer_model_dir_key
}
"
"
${
infer_model_dir_value
}
"
)
set_model_filename
=
$(
func_set_params
"
${
model_filename_key
}
"
"
${
model_filename_value
}
"
)
set_params_filename
=
$(
func_set_params
"
${
params_filename_key
}
"
"
${
params_filename_value
}
"
)
set_serving_server
=
$(
func_set_params
"
${
serving_server_key
}
"
"
${
serving_server_value
}
"
)
set_serving_client
=
$(
func_set_params
"
${
serving_client_key
}
"
"
${
serving_client_value
}
"
)
trans_model_cmd
=
"
${
python
}
${
trans_model_py
}
${
set_dirname
}
${
set_model_filename
}
${
set_params_filename
}
${
set_serving_server
}
${
set_serving_client
}
"
eval
$trans_model_cmd
cd
${
serving_dir_value
}
echo
$PWD
unset
https_proxy
unset
http_proxy
for
use_gpu
in
${
web_use_gpu_list
[*]
}
;
do
echo
${
ues_gpu
}
if
[
${
use_gpu
}
=
"null"
]
;
then
for
use_mkldnn
in
${
web_use_mkldnn_list
[*]
}
;
do
if
[
${
use_mkldnn
}
=
"False"
]
;
then
continue
fi
for
threads
in
${
web_cpu_threads_list
[*]
}
;
do
_save_log_path
=
"
${
_log_path
}
/server_cpu_usemkldnn_
${
use_mkldnn
}
_threads_
${
threads
}
_batchsize_1.log"
set_cpu_threads
=
$(
func_set_params
"
${
web_cpu_threads_key
}
"
"
${
threads
}
"
)
web_service_cmd
=
"
${
python
}
${
web_service_py
}
${
web_use_gpu_key
}
=
${
use_gpu
}
${
web_use_mkldnn_key
}
=
${
use_mkldnn
}
${
set_cpu_threads
}
&>
${
_save_log_path
}
&"
eval
$web_service_cmd
sleep
2s
pipeline_cmd
=
"
${
python
}
${
pipeline_py
}
"
eval
$pipeline_cmd
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
$last_status
"
${
pipeline_cmd
}
"
"
${
status_log
}
"
PID
=
$!
kill
$PID
sleep
2s
ps ux |
grep
-E
'web_service|pipeline'
|
awk
'{print $2}'
| xargs
kill
-s
9
done
done
elif
[
${
use_gpu
}
=
"0"
]
;
then
for
use_trt
in
${
web_use_trt_list
[*]
}
;
do
for
precision
in
${
web_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
}
=
"Falg_quantse"
||
${
precision
}
=
~
"int8"
]]
;
then
continue
fi
_save_log_path
=
"
${
_log_path
}
/infer_gpu_usetrt_
${
use_trt
}
_precision_
${
precision
}
_batchsize_1.log"
set_tensorrt
=
$(
func_set_params
"
${
web_use_trt_key
}
"
"
${
use_trt
}
"
)
set_precision
=
$(
func_set_params
"
${
web_precision_key
}
"
"
${
precision
}
"
)
web_service_cmd
=
"
${
python
}
${
web_service_py
}
${
web_use_gpu_key
}
=
${
use_gpu
}
${
set_tensorrt
}
${
set_precision
}
&>
${
_save_log_path
}
& "
eval
$web_service_cmd
sleep
2s
pipeline_cmd
=
"
${
python
}
${
pipeline_py
}
"
eval
$pipeline_cmd
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
$last_status
"
${
pipeline_cmd
}
"
"
${
status_log
}
"
PID
=
$!
kill
$PID
sleep
2s
ps ux |
grep
-E
'web_service|pipeline'
|
awk
'{print $2}'
| xargs
kill
-s
9
done
done
else
echo
"Does not support hardware other than CPU and GPU Currently!"
fi
done
}
function
func_cpp_inference
(){
IFS
=
'|'
...
...
@@ -267,7 +369,8 @@ function func_cpp_inference(){
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 "
set_infer_params1
=
$(
func_set_params
"
${
cpp_infer_key1
}
"
"
${
cpp_infer_value1
}
"
)
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
}
${
set_infer_params1
}
>
${
_save_log_path
}
2>&1 "
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
...
...
@@ -295,7 +398,8 @@ function func_cpp_inference(){
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 "
set_infer_params1
=
$(
func_set_params
"
${
cpp_infer_key1
}
"
"
${
cpp_infer_value1
}
"
)
command
=
"
${
_script
}
${
cpp_use_gpu_key
}
=
${
use_gpu
}
${
set_tensorrt
}
${
set_precision
}
${
set_model_dir
}
${
set_batchsize
}
${
set_infer_data
}
${
set_benchmark
}
${
set_infer_params1
}
>
${
_save_log_path
}
2>&1 "
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
...
...
@@ -332,9 +436,7 @@ if [ ${MODE} = "infer" ]; then
export_cmd
=
"
${
python
}
${
norm_export
}
${
set_export_weight
}
${
set_save_infer_key
}
"
eval
$export_cmd
status_export
=
$?
if
[
${
status_export
}
=
0
]
;
then
status_check
$status_export
"
${
export_cmd
}
"
"
${
status_log
}
"
fi
else
save_infer_dir
=
${
infer_model
}
fi
...
...
@@ -363,6 +465,20 @@ elif [ ${MODE} = "cpp_infer" ]; then
Count
=
$((
$Count
+
1
))
done
elif
[
${
MODE
}
=
"serving_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
=
"|"
#run serving
func_serving
"
${
web_service_cmd
}
"
else
IFS
=
"|"
export
Count
=
0
...
...
tools/eval.py
View file @
ac98415b
...
...
@@ -55,6 +55,7 @@ def main():
model
=
build_model
(
config
[
'Architecture'
])
use_srn
=
config
[
'Architecture'
][
'algorithm'
]
==
"SRN"
use_sar
=
config
[
'Architecture'
][
'algorithm'
]
==
"SAR"
if
"model_type"
in
config
[
'Architecture'
].
keys
():
model_type
=
config
[
'Architecture'
][
'model_type'
]
else
:
...
...
@@ -71,7 +72,7 @@ def main():
# start eval
metric
=
program
.
eval
(
model
,
valid_dataloader
,
post_process_class
,
eval_class
,
model_type
,
use_srn
)
eval_class
,
model_type
,
use_srn
,
use_sar
)
logger
.
info
(
'metric eval ***************'
)
for
k
,
v
in
metric
.
items
():
logger
.
info
(
'{}:{}'
.
format
(
k
,
v
))
...
...
tools/infer/predict_e2e.py
View file @
ac98415b
...
...
@@ -141,6 +141,7 @@ if __name__ == "__main__":
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
img
=
cv2
.
imread
(
image_file
)
img
=
img
[:,
:,
::
-
1
]
if
img
is
None
:
logger
.
info
(
"error in loading image:{}"
.
format
(
image_file
))
continue
...
...
tools/infer/predict_system.py
View file @
ac98415b
...
...
@@ -173,6 +173,9 @@ def main(args):
logger
.
info
(
"The predict total time is {}"
.
format
(
time
.
time
()
-
_st
))
logger
.
info
(
"
\n
The predict total time is {}"
.
format
(
total_time
))
if
args
.
benchmark
:
text_sys
.
text_detector
.
autolog
.
report
()
text_sys
.
text_recognizer
.
autolog
.
report
()
if
__name__
==
"__main__"
:
...
...
tools/infer/utility.py
View file @
ac98415b
...
...
@@ -243,11 +243,11 @@ def create_predictor(args, mode, logger):
max_input_shape
.
update
(
max_pact_shape
)
opt_input_shape
.
update
(
opt_pact_shape
)
elif
mode
==
"rec"
:
min_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
32
,
10
]}
min_input_shape
=
{
"x"
:
[
1
,
3
,
32
,
10
]}
max_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
32
,
2000
]}
opt_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
32
,
320
]}
elif
mode
==
"cls"
:
min_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
48
,
10
]}
min_input_shape
=
{
"x"
:
[
1
,
3
,
48
,
10
]}
max_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
48
,
2000
]}
opt_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
48
,
320
]}
else
:
...
...
tools/infer_rec.py
View file @
ac98415b
...
...
@@ -74,6 +74,10 @@ def main():
'image'
,
'encoder_word_pos'
,
'gsrm_word_pos'
,
'gsrm_slf_attn_bias1'
,
'gsrm_slf_attn_bias2'
]
elif
config
[
'Architecture'
][
'algorithm'
]
==
"SAR"
:
op
[
op_name
][
'keep_keys'
]
=
[
'image'
,
'valid_ratio'
]
else
:
op
[
op_name
][
'keep_keys'
]
=
[
'image'
]
transforms
.
append
(
op
)
...
...
@@ -106,11 +110,16 @@ def main():
paddle
.
to_tensor
(
gsrm_slf_attn_bias1_list
),
paddle
.
to_tensor
(
gsrm_slf_attn_bias2_list
)
]
if
config
[
'Architecture'
][
'algorithm'
]
==
"SAR"
:
valid_ratio
=
np
.
expand_dims
(
batch
[
-
1
],
axis
=
0
)
img_metas
=
[
paddle
.
to_tensor
(
valid_ratio
)]
images
=
np
.
expand_dims
(
batch
[
0
],
axis
=
0
)
images
=
paddle
.
to_tensor
(
images
)
if
config
[
'Architecture'
][
'algorithm'
]
==
"SRN"
:
preds
=
model
(
images
,
others
)
elif
config
[
'Architecture'
][
'algorithm'
]
==
"SAR"
:
preds
=
model
(
images
,
img_metas
)
else
:
preds
=
model
(
images
)
post_result
=
post_process_class
(
preds
)
...
...
tools/program.py
View file @
ac98415b
...
...
@@ -187,7 +187,7 @@ def train(config,
use_srn
=
config
[
'Architecture'
][
'algorithm'
]
==
"SRN"
use_nrtr
=
config
[
'Architecture'
][
'algorithm'
]
==
"NRTR"
use_sar
=
config
[
'Architecture'
][
'algorithm'
]
==
'SAR'
try
:
model_type
=
config
[
'Architecture'
][
'model_type'
]
except
:
...
...
@@ -215,7 +215,7 @@ def train(config,
images
=
batch
[
0
]
if
use_srn
:
model_average
=
True
if
use_srn
or
model_type
==
'table'
or
use_nrtr
:
if
use_srn
or
model_type
==
'table'
or
use_nrtr
or
use_sar
:
preds
=
model
(
images
,
data
=
batch
[
1
:])
else
:
preds
=
model
(
images
)
...
...
@@ -279,7 +279,8 @@ def train(config,
post_process_class
,
eval_class
,
model_type
,
use_srn
=
use_srn
)
use_srn
=
use_srn
,
use_sar
=
use_sar
)
cur_metric_str
=
'cur metric, {}'
.
format
(
', '
.
join
(
[
'{}: {}'
.
format
(
k
,
v
)
for
k
,
v
in
cur_metric
.
items
()]))
logger
.
info
(
cur_metric_str
)
...
...
@@ -351,7 +352,8 @@ def eval(model,
post_process_class
,
eval_class
,
model_type
,
use_srn
=
False
):
use_srn
=
False
,
use_sar
=
False
):
model
.
eval
()
with
paddle
.
no_grad
():
total_frame
=
0.0
...
...
@@ -364,7 +366,7 @@ def eval(model,
break
images
=
batch
[
0
]
start
=
time
.
time
()
if
use_srn
or
model_type
==
'table'
:
if
use_srn
or
model_type
==
'table'
or
use_sar
:
preds
=
model
(
images
,
data
=
batch
[
1
:])
else
:
preds
=
model
(
images
)
...
...
@@ -400,7 +402,7 @@ def preprocess(is_train=False):
alg
=
config
[
'Architecture'
][
'algorithm'
]
assert
alg
in
[
'EAST'
,
'DB'
,
'SAST'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
,
'SRN'
,
'CLS'
,
'PGNet'
,
'Distillation'
,
'NRTR'
,
'TableAttn'
,
'PSE'
'CLS'
,
'PGNet'
,
'Distillation'
,
'NRTR'
,
'TableAttn'
,
'SAR'
,
'PSE'
]
device
=
'gpu:{}'
.
format
(
dist
.
ParallelEnv
().
dev_id
)
if
use_gpu
else
'cpu'
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment