Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
c261d0da
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看板
未验证
提交
c261d0da
编写于
7月 13, 2021
作者:
D
Double_V
提交者:
GitHub
7月 13, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3268 from tink2123/autolog_rec
add autolog for infer_rec
上级
8e8daa22
fddef391
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
83 addition
and
18 deletion
+83
-18
doc/doc_en/update_en.md
doc/doc_en/update_en.md
+0
-2
test/ocr_rec_params.txt
test/ocr_rec_params.txt
+35
-0
test/prepare.sh
test/prepare.sh
+18
-12
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+30
-4
未找到文件。
doc/doc_en/update_en.md
浏览文件 @
c261d0da
...
@@ -15,8 +15,6 @@
...
@@ -15,8 +15,6 @@
-
2020.6.8 Add
[
datasets
](
./datasets_en.md
)
and keep updating
-
2020.6.8 Add
[
datasets
](
./datasets_en.md
)
and keep updating
-
2020.6.5 Support exporting
`attention`
model to
`inference_model`
-
2020.6.5 Support exporting
`attention`
model to
`inference_model`
-
2020.6.5 Support separate prediction and recognition, output result score
-
2020.6.5 Support separate prediction and recognition, output result score
-
2020.6.5 Support exporting
`attention`
model to
`inference_model`
-
2020.6.5 Support separate prediction and recognition, output result score
-
2020.5.30 Provide Lightweight Chinese OCR online experience
-
2020.5.30 Provide Lightweight Chinese OCR online experience
-
2020.5.30 Model prediction and training support on Windows system
-
2020.5.30 Model prediction and training support on Windows system
-
2020.5.30 Open source general Chinese OCR model
-
2020.5.30 Open source general Chinese OCR model
...
...
test/ocr_rec_params.txt
0 → 100644
浏览文件 @
c261d0da
model_name:ocr_rec
python:python
gpu_list:0|0,1
Global.auto_cast:null
Global.epoch_num:10
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:
Global.use_gpu:
Global.pretrained_model:null
trainer:norm|pact
norm_train:tools/train.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml
quant_train:deploy/slim/quantization/quant.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml
fpgm_train:null
distill_train:null
eval:tools/eval.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml -o
Global.save_inference_dir:./output/
Global.pretrained_model:
norm_export:tools/export_model.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml -o
quant_export:deploy/slim/quantization/export_model.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml -o
fpgm_export:null
distill_export:null
inference:tools/infer/predict_rec.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1
--use_tensorrt:True|False
--precision:fp32|fp16|int8
--rec_model_dir:./inference/ch_ppocr_mobile_v2.0_rec_infer/
--image_dir:./inference/rec_inference
--save_log_path:./test/output/
\ No newline at end of file
test/prepare.sh
浏览文件 @
c261d0da
...
@@ -29,19 +29,21 @@ train_model_list=$(func_parser_value "${lines[0]}")
...
@@ -29,19 +29,21 @@ train_model_list=$(func_parser_value "${lines[0]}")
trainer_list
=
$(
func_parser_value
"
${
lines
[10]
}
"
)
trainer_list
=
$(
func_parser_value
"
${
lines
[10]
}
"
)
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer']
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer']
MODE
=
$2
MODE
=
$2
# prepare pretrained weights and dataset
# prepare pretrained weights and dataset
wget
-nc
-P
./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams
if
[
${
train_model_list
[*]
}
=
"ocr_det"
]
;
then
wget
-nc
-P
./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar
wget
-nc
-P
./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams
cd
pretrain_models
&&
tar
xf det_mv3_db_v2.0_train.tar
&&
cd
../
wget
-nc
-P
./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar
cd
pretrain_models
&&
tar
xf det_mv3_db_v2.0_train.tar
&&
cd
../
fi
if
[
${
MODE
}
=
"lite_train_infer"
]
;
then
if
[
${
MODE
}
=
"lite_train_infer"
]
;
then
# pretrain lite train data
# pretrain lite train data
rm
-rf
./train_data/icdar2015
rm
-rf
./train_data/icdar2015
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar
cd
./train_data/
&&
tar
xf icdar2015_lite.tar
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
# todo change to bcebos
cd
./train_data/
&&
tar
xf icdar2015_lite.tar
&&
tar
xf ic15_data.tar
ln
-s
./icdar2015_lite ./icdar2015
ln
-s
./icdar2015_lite ./icdar2015
cd
../
cd
../
epoch
=
10
epoch
=
10
...
@@ -49,13 +51,15 @@ if [ ${MODE} = "lite_train_infer" ];then
...
@@ -49,13 +51,15 @@ if [ ${MODE} = "lite_train_infer" ];then
elif
[
${
MODE
}
=
"whole_train_infer"
]
;
then
elif
[
${
MODE
}
=
"whole_train_infer"
]
;
then
rm
-rf
./train_data/icdar2015
rm
-rf
./train_data/icdar2015
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar
cd
./train_data/
&&
tar
xf icdar2015.tar
&&
cd
../
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
cd
./train_data/
&&
tar
xf icdar2015.tar
&&
tar
xf ic15_data.tar
&&
cd
../
epoch
=
500
epoch
=
500
eval_batch_step
=
200
eval_batch_step
=
200
elif
[
${
MODE
}
=
"whole_infer"
]
;
then
elif
[
${
MODE
}
=
"whole_infer"
]
;
then
rm
-rf
./train_data/icdar2015
rm
-rf
./train_data/icdar2015
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar
cd
./train_data/
&&
tar
xf icdar2015_infer.tar
wget
-nc
-P
./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
cd
./train_data/
&&
tar
xf icdar2015_infer.tar
&&
tar
xf ic15_data.tar
ln
-s
./icdar2015_infer ./icdar2015
ln
-s
./icdar2015_infer ./icdar2015
cd
../
cd
../
epoch
=
10
epoch
=
10
...
@@ -88,9 +92,11 @@ for train_model in ${train_model_list[*]}; do
...
@@ -88,9 +92,11 @@ for train_model in ${train_model_list[*]}; do
elif
[
${
train_model
}
=
"ocr_rec"
]
;
then
elif
[
${
train_model
}
=
"ocr_rec"
]
;
then
model_name
=
"ocr_rec"
model_name
=
"ocr_rec"
yml_file
=
"configs/rec/rec_mv3_none_bilstm_ctc.yml"
yml_file
=
"configs/rec/rec_mv3_none_bilstm_ctc.yml"
wget
-nc
-P
./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_rec_data_200.tar
wget
-nc
-P
./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/rec_inference.tar
cd
./inference
&&
tar
xf ch_rec_data_200.tar
&&
cd
../
cd
./inference
&&
tar
xf rec_inference.tar
&&
cd
../
img_dir
=
"./inference/ch_rec_data_200/"
img_dir
=
"./inference/rec_inference/"
data_dir
=
./inference/rec_inference
data_label_file
=[
./inference/rec_inference/rec_gt_test.txt]
fi
fi
# eval
# eval
...
...
tools/infer/predict_rec.py
浏览文件 @
c261d0da
...
@@ -64,6 +64,24 @@ class TextRecognizer(object):
...
@@ -64,6 +64,24 @@ class TextRecognizer(object):
self
.
postprocess_op
=
build_post_process
(
postprocess_params
)
self
.
postprocess_op
=
build_post_process
(
postprocess_params
)
self
.
predictor
,
self
.
input_tensor
,
self
.
output_tensors
,
self
.
config
=
\
self
.
predictor
,
self
.
input_tensor
,
self
.
output_tensors
,
self
.
config
=
\
utility
.
create_predictor
(
args
,
'rec'
,
logger
)
utility
.
create_predictor
(
args
,
'rec'
,
logger
)
self
.
benchmark
=
args
.
benchmark
if
args
.
benchmark
:
import
auto_log
pid
=
os
.
getpid
()
self
.
autolog
=
auto_log
.
AutoLogger
(
model_name
=
"rec"
,
model_precision
=
args
.
precision
,
batch_size
=
args
.
rec_batch_num
,
data_shape
=
"dynamic"
,
save_path
=
args
.
save_log_path
,
inference_config
=
self
.
config
,
pids
=
pid
,
process_name
=
None
,
gpu_ids
=
0
if
args
.
use_gpu
else
None
,
time_keys
=
[
'preprocess_time'
,
'inference_time'
,
'postprocess_time'
],
warmup
=
10
)
def
resize_norm_img
(
self
,
img
,
max_wh_ratio
):
def
resize_norm_img
(
self
,
img
,
max_wh_ratio
):
imgC
,
imgH
,
imgW
=
self
.
rec_image_shape
imgC
,
imgH
,
imgW
=
self
.
rec_image_shape
...
@@ -168,6 +186,8 @@ class TextRecognizer(object):
...
@@ -168,6 +186,8 @@ class TextRecognizer(object):
rec_res
=
[[
''
,
0.0
]]
*
img_num
rec_res
=
[[
''
,
0.0
]]
*
img_num
batch_num
=
self
.
rec_batch_num
batch_num
=
self
.
rec_batch_num
st
=
time
.
time
()
st
=
time
.
time
()
if
self
.
benchmark
:
self
.
autolog
.
times
.
start
()
for
beg_img_no
in
range
(
0
,
img_num
,
batch_num
):
for
beg_img_no
in
range
(
0
,
img_num
,
batch_num
):
end_img_no
=
min
(
img_num
,
beg_img_no
+
batch_num
)
end_img_no
=
min
(
img_num
,
beg_img_no
+
batch_num
)
norm_img_batch
=
[]
norm_img_batch
=
[]
...
@@ -196,6 +216,8 @@ class TextRecognizer(object):
...
@@ -196,6 +216,8 @@ class TextRecognizer(object):
norm_img_batch
.
append
(
norm_img
[
0
])
norm_img_batch
.
append
(
norm_img
[
0
])
norm_img_batch
=
np
.
concatenate
(
norm_img_batch
)
norm_img_batch
=
np
.
concatenate
(
norm_img_batch
)
norm_img_batch
=
norm_img_batch
.
copy
()
norm_img_batch
=
norm_img_batch
.
copy
()
if
self
.
benchmark
:
self
.
autolog
.
times
.
stamp
()
if
self
.
rec_algorithm
==
"SRN"
:
if
self
.
rec_algorithm
==
"SRN"
:
encoder_word_pos_list
=
np
.
concatenate
(
encoder_word_pos_list
)
encoder_word_pos_list
=
np
.
concatenate
(
encoder_word_pos_list
)
...
@@ -222,6 +244,8 @@ class TextRecognizer(object):
...
@@ -222,6 +244,8 @@ class TextRecognizer(object):
for
output_tensor
in
self
.
output_tensors
:
for
output_tensor
in
self
.
output_tensors
:
output
=
output_tensor
.
copy_to_cpu
()
output
=
output_tensor
.
copy_to_cpu
()
outputs
.
append
(
output
)
outputs
.
append
(
output
)
if
self
.
benchmark
:
self
.
autolog
.
times
.
stamp
()
preds
=
{
"predict"
:
outputs
[
2
]}
preds
=
{
"predict"
:
outputs
[
2
]}
else
:
else
:
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
...
@@ -231,11 +255,14 @@ class TextRecognizer(object):
...
@@ -231,11 +255,14 @@ class TextRecognizer(object):
for
output_tensor
in
self
.
output_tensors
:
for
output_tensor
in
self
.
output_tensors
:
output
=
output_tensor
.
copy_to_cpu
()
output
=
output_tensor
.
copy_to_cpu
()
outputs
.
append
(
output
)
outputs
.
append
(
output
)
if
self
.
benchmark
:
self
.
autolog
.
times
.
stamp
()
preds
=
outputs
[
0
]
preds
=
outputs
[
0
]
rec_result
=
self
.
postprocess_op
(
preds
)
rec_result
=
self
.
postprocess_op
(
preds
)
for
rno
in
range
(
len
(
rec_result
)):
for
rno
in
range
(
len
(
rec_result
)):
rec_res
[
indices
[
beg_img_no
+
rno
]]
=
rec_result
[
rno
]
rec_res
[
indices
[
beg_img_no
+
rno
]]
=
rec_result
[
rno
]
if
self
.
benchmark
:
self
.
autolog
.
times
.
end
(
stamp
=
True
)
return
rec_res
,
time
.
time
()
-
st
return
rec_res
,
time
.
time
()
-
st
...
@@ -251,9 +278,6 @@ def main(args):
...
@@ -251,9 +278,6 @@ def main(args):
for
i
in
range
(
10
):
for
i
in
range
(
10
):
res
=
text_recognizer
([
img
])
res
=
text_recognizer
([
img
])
cpu_mem
,
gpu_mem
,
gpu_util
=
0
,
0
,
0
count
=
0
for
image_file
in
image_file_list
:
for
image_file
in
image_file_list
:
img
,
flag
=
check_and_read_gif
(
image_file
)
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
if
not
flag
:
...
@@ -273,6 +297,8 @@ def main(args):
...
@@ -273,6 +297,8 @@ def main(args):
for
ino
in
range
(
len
(
img_list
)):
for
ino
in
range
(
len
(
img_list
)):
logger
.
info
(
"Predicts of {}:{}"
.
format
(
valid_image_file_list
[
ino
],
logger
.
info
(
"Predicts of {}:{}"
.
format
(
valid_image_file_list
[
ino
],
rec_res
[
ino
]))
rec_res
[
ino
]))
if
args
.
benchmark
:
text_recognizer
.
autolog
.
report
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录