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
cb2195e3
Commit
cb2195e3
authored
Jul 28, 2021
by
Leif
Browse files
Merge remote-tracking branch 'origin/dygraph' into dygraph
parents
45391ef0
75aa6f2f
Changes
27
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
32 deletions
+96
-32
ppocr/modeling/architectures/distillation_model.py
ppocr/modeling/architectures/distillation_model.py
+1
-1
ppocr/utils/gen_label.py
ppocr/utils/gen_label.py
+12
-10
test/ocr_rec_params.txt
test/ocr_rec_params.txt
+35
-0
test/prepare.sh
test/prepare.sh
+18
-12
tools/infer/predict_cls.py
tools/infer/predict_cls.py
+0
-2
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+30
-4
tools/infer/utility.py
tools/infer/utility.py
+0
-3
No files found.
ppocr/modeling/architectures/distillation_model.py
View file @
cb2195e3
...
...
@@ -46,7 +46,7 @@ class DistillationModel(nn.Layer):
pretrained
=
model_config
.
pop
(
"pretrained"
)
model
=
BaseModel
(
model_config
)
if
pretrained
is
not
None
:
model
=
load_pretrained_params
(
model
,
pretrained
)
load_pretrained_params
(
model
,
pretrained
)
if
freeze_params
:
for
param
in
model
.
parameters
():
param
.
trainable
=
False
...
...
ppocr/utils/gen_label.py
View file @
cb2195e3
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
Licensed under the Apache License, Version 2.0 (the "License");
#
you may not use this file except in compliance with the License.
#
You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#
Unless required by applicable law or agreed to in writing, software
#
distributed under the License is distributed on an "AS IS" BASIS,
#
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
See the License for the specific language governing permissions and
#
limitations under the License.
import
os
import
argparse
import
json
...
...
@@ -31,7 +31,9 @@ def gen_det_label(root_path, input_dir, out_label):
for
label_file
in
os
.
listdir
(
input_dir
):
img_path
=
root_path
+
label_file
[
3
:
-
4
]
+
".jpg"
label
=
[]
with
open
(
os
.
path
.
join
(
input_dir
,
label_file
),
'r'
)
as
f
:
with
open
(
os
.
path
.
join
(
input_dir
,
label_file
),
'r'
,
encoding
=
'utf-8-sig'
)
as
f
:
for
line
in
f
.
readlines
():
tmp
=
line
.
strip
(
"
\n\r
"
).
replace
(
"
\xef\xbb\xbf
"
,
""
).
split
(
','
)
...
...
test/ocr_rec_params.txt
0 → 100644
View file @
cb2195e3
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
View file @
cb2195e3
...
...
@@ -29,19 +29,21 @@ train_model_list=$(func_parser_value "${lines[0]}")
trainer_list
=
$(
func_parser_value
"
${
lines
[10]
}
"
)
# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer']
MODE
=
$2
# 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
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
../
if
[
${
train_model_list
[*]
}
=
"ocr_det"
]
;
then
wget
-nc
-P
./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams
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
# pretrain lite train data
rm
-rf
./train_data/icdar2015
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
cd
../
epoch
=
10
...
...
@@ -49,13 +51,15 @@ if [ ${MODE} = "lite_train_infer" ];then
elif
[
${
MODE
}
=
"whole_train_infer"
]
;
then
rm
-rf
./train_data/icdar2015
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
eval_batch_step
=
200
elif
[
${
MODE
}
=
"whole_infer"
]
;
then
rm
-rf
./train_data/icdar2015
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
cd
../
epoch
=
10
...
...
@@ -88,9 +92,11 @@ for train_model in ${train_model_list[*]}; do
elif
[
${
train_model
}
=
"ocr_rec"
]
;
then
model_name
=
"ocr_rec"
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
cd
./inference
&&
tar
xf ch_rec_data_200.tar
&&
cd
../
img_dir
=
"./inference/ch_rec_data_200/"
wget
-nc
-P
./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/rec_inference.tar
cd
./inference
&&
tar
xf rec_inference.tar
&&
cd
../
img_dir
=
"./inference/rec_inference/"
data_dir
=
./inference/rec_inference
data_label_file
=[
./inference/rec_inference/rec_gt_test.txt]
fi
# eval
...
...
tools/infer/predict_cls.py
View file @
cb2195e3
...
...
@@ -112,7 +112,6 @@ class TextClassifier(object):
if
'180'
in
label
and
score
>
self
.
cls_thresh
:
img_list
[
indices
[
beg_img_no
+
rno
]]
=
cv2
.
rotate
(
img_list
[
indices
[
beg_img_no
+
rno
]],
1
)
elapse
=
time
.
time
()
-
starttime
return
img_list
,
cls_res
,
elapse
...
...
@@ -146,7 +145,6 @@ def main(args):
cls_res
[
ino
]))
logger
.
info
(
"The predict time about text angle classify module is as follows: "
)
text_classifier
.
cls_times
.
info
(
average
=
False
)
if
__name__
==
"__main__"
:
...
...
tools/infer/predict_rec.py
View file @
cb2195e3
...
...
@@ -64,6 +64,24 @@ class TextRecognizer(object):
self
.
postprocess_op
=
build_post_process
(
postprocess_params
)
self
.
predictor
,
self
.
input_tensor
,
self
.
output_tensors
,
self
.
config
=
\
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
):
imgC
,
imgH
,
imgW
=
self
.
rec_image_shape
...
...
@@ -168,6 +186,8 @@ class TextRecognizer(object):
rec_res
=
[[
''
,
0.0
]]
*
img_num
batch_num
=
self
.
rec_batch_num
st
=
time
.
time
()
if
self
.
benchmark
:
self
.
autolog
.
times
.
start
()
for
beg_img_no
in
range
(
0
,
img_num
,
batch_num
):
end_img_no
=
min
(
img_num
,
beg_img_no
+
batch_num
)
norm_img_batch
=
[]
...
...
@@ -196,6 +216,8 @@ class TextRecognizer(object):
norm_img_batch
.
append
(
norm_img
[
0
])
norm_img_batch
=
np
.
concatenate
(
norm_img_batch
)
norm_img_batch
=
norm_img_batch
.
copy
()
if
self
.
benchmark
:
self
.
autolog
.
times
.
stamp
()
if
self
.
rec_algorithm
==
"SRN"
:
encoder_word_pos_list
=
np
.
concatenate
(
encoder_word_pos_list
)
...
...
@@ -222,6 +244,8 @@ class TextRecognizer(object):
for
output_tensor
in
self
.
output_tensors
:
output
=
output_tensor
.
copy_to_cpu
()
outputs
.
append
(
output
)
if
self
.
benchmark
:
self
.
autolog
.
times
.
stamp
()
preds
=
{
"predict"
:
outputs
[
2
]}
else
:
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
...
...
@@ -231,11 +255,14 @@ class TextRecognizer(object):
for
output_tensor
in
self
.
output_tensors
:
output
=
output_tensor
.
copy_to_cpu
()
outputs
.
append
(
output
)
if
self
.
benchmark
:
self
.
autolog
.
times
.
stamp
()
preds
=
outputs
[
0
]
rec_result
=
self
.
postprocess_op
(
preds
)
for
rno
in
range
(
len
(
rec_result
)):
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
...
...
@@ -251,9 +278,6 @@ def main(args):
for
i
in
range
(
10
):
res
=
text_recognizer
([
img
])
cpu_mem
,
gpu_mem
,
gpu_util
=
0
,
0
,
0
count
=
0
for
image_file
in
image_file_list
:
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
...
...
@@ -273,6 +297,8 @@ def main(args):
for
ino
in
range
(
len
(
img_list
)):
logger
.
info
(
"Predicts of {}:{}"
.
format
(
valid_image_file_list
[
ino
],
rec_res
[
ino
]))
if
args
.
benchmark
:
text_recognizer
.
autolog
.
report
()
if
__name__
==
"__main__"
:
...
...
tools/infer/utility.py
View file @
cb2195e3
...
...
@@ -24,9 +24,6 @@ from paddle import inference
import
time
from
ppocr.utils.logging
import
get_logger
logger
=
get_logger
()
def
str2bool
(
v
):
return
v
.
lower
()
in
(
"true"
,
"t"
,
"1"
)
...
...
Prev
1
2
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