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
2b3f89f0
Commit
2b3f89f0
authored
Apr 27, 2022
by
LDOUBLEV
Browse files
Merge branch 'dygraph' of
https://github.com/PaddlePaddle/PaddleOCR
into dygraph
parents
591b92e8
882e6e54
Changes
59
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
670 additions
and
165 deletions
+670
-165
test_tipc/configs/ch_PP-OCRv2_rec/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_mobile_v2.0_det/det_mv3_db.yml
test_tipc/configs/ch_ppocr_mobile_v2.0_det/det_mv3_db.yml
+0
-126
test_tipc/configs/ch_ppocr_mobile_v2.0_det/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+12
-10
test_tipc/configs/ch_ppocr_mobile_v2.0_det_FPGM/train_infer_python.txt
...figs/ch_ppocr_mobile_v2.0_det_FPGM/train_infer_python.txt
+1
-1
test_tipc/configs/ch_ppocr_mobile_v2.0_det_FPGM/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_mobile_v2.0_det_PACT/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_mobile_v2.0_rec/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_server_v2.0_det/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
test_tipc/configs/ch_ppocr_server_v2.0_rec/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
...train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
+53
-0
tools/eval.py
tools/eval.py
+30
-4
tools/export_model.py
tools/export_model.py
+37
-2
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+28
-9
tools/infer/utility.py
tools/infer/utility.py
+6
-4
tools/infer_rec.py
tools/infer_rec.py
+22
-2
tools/program.py
tools/program.py
+16
-4
tools/train.py
tools/train.py
+41
-3
No files found.
test_tipc/configs/ch_PP-OCRv2_rec/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:PPOCRv2_ocr_rec
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=3|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=16|whole_train_whole_infer=128
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./inference/rec_inference
null:null
##
trainer:norm_train
norm_train:tools/train.py -c test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml -o
pact_train:null
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:tools/export_model.py -c test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml -o
quant_export:
fpgm_export:
distill_export:null
export1:null
export2:null
inference_dir:Student
infer_model:./inference/ch_PP-OCRv2_rec_infer
infer_export:null
infer_quant:False
inference:tools/infer/predict_rec.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1|6
--use_tensorrt:False|True
--precision:fp32|int8
--rec_model_dir:
--image_dir:./inference/rec_inference
null:null
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,32,320]}]
test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_PPOCRv2_rec_PACT
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=3|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=16|whole_train_whole_infer=128
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./inference/rec_inference
null:null
##
trainer:pact_train
norm_train:null
pact_train:deploy/slim/quantization/quant.py -c test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml -o
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:null
quant_export:deploy/slim/quantization/export_model.py -c test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml -o
fpgm_export: null
distill_export:null
export1:null
export2:null
inference_dir:Student
infer_model:./inference/ch_PP-OCRv2_rec_slim_quant_infer
infer_export:null
infer_quant:True
inference:tools/infer/predict_rec.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1|6
--use_tensorrt:False|True
--precision:fp32|int8
--rec_model_dir:
--image_dir:./inference/rec_inference
null:null
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,32,320]}]
test_tipc/configs/ch_ppocr_mobile_v2.0_det/det_mv3_db.yml
deleted
100644 → 0
View file @
591b92e8
Global
:
use_gpu
:
false
epoch_num
:
5
log_smooth_window
:
20
print_batch_step
:
1
save_model_dir
:
./output/db_mv3/
save_epoch_step
:
1200
# evaluation is run every 2000 iterations
eval_batch_step
:
[
0
,
400
]
cal_metric_during_train
:
False
pretrained_model
:
./pretrain_models/MobileNetV3_large_x0_5_pretrained
checkpoints
:
save_inference_dir
:
use_visualdl
:
False
infer_img
:
doc/imgs_en/img_10.jpg
save_res_path
:
./output/det_db/predicts_db.txt
Architecture
:
model_type
:
det
algorithm
:
DB
Transform
:
Backbone
:
name
:
MobileNetV3
scale
:
0.5
model_name
:
large
disable_se
:
False
Neck
:
name
:
DBFPN
out_channels
:
256
Head
:
name
:
DBHead
k
:
50
Loss
:
name
:
DBLoss
balance_loss
:
true
main_loss_type
:
DiceLoss
alpha
:
5
beta
:
10
ohem_ratio
:
3
Optimizer
:
name
:
Adam
#Momentum
#momentum: 0.9
beta1
:
0.9
beta2
:
0.999
lr
:
learning_rate
:
0.001
regularizer
:
name
:
'
L2'
factor
:
0
PostProcess
:
name
:
DBPostProcess
thresh
:
0.3
box_thresh
:
0.6
max_candidates
:
1000
unclip_ratio
:
1.5
Metric
:
name
:
DetMetric
main_indicator
:
hmean
Train
:
dataset
:
name
:
SimpleDataSet
data_dir
:
./train_data/icdar2015/text_localization/
label_file_list
:
-
./train_data/icdar2015/text_localization/train_icdar2015_label.txt
ratio_list
:
[
1.0
]
transforms
:
-
DecodeImage
:
# load image
img_mode
:
BGR
channel_first
:
False
-
DetLabelEncode
:
# Class handling label
-
Resize
:
size
:
[
640
,
640
]
-
MakeBorderMap
:
shrink_ratio
:
0.4
thresh_min
:
0.3
thresh_max
:
0.7
-
MakeShrinkMap
:
shrink_ratio
:
0.4
min_text_size
:
8
-
NormalizeImage
:
scale
:
1./255.
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
hwc'
-
ToCHWImage
:
-
KeepKeys
:
keep_keys
:
[
'
image'
,
'
threshold_map'
,
'
threshold_mask'
,
'
shrink_map'
,
'
shrink_mask'
]
# the order of the dataloader list
loader
:
shuffle
:
False
drop_last
:
False
batch_size_per_card
:
1
num_workers
:
0
use_shared_memory
:
False
Eval
:
dataset
:
name
:
SimpleDataSet
data_dir
:
./train_data/icdar2015/text_localization/
label_file_list
:
-
./train_data/icdar2015/text_localization/test_icdar2015_label.txt
transforms
:
-
DecodeImage
:
# load image
img_mode
:
BGR
channel_first
:
False
-
DetLabelEncode
:
# Class handling label
-
DetResizeForTest
:
image_shape
:
[
736
,
1280
]
-
NormalizeImage
:
scale
:
1./255.
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
hwc'
-
ToCHWImage
:
-
KeepKeys
:
keep_keys
:
[
'
image'
,
'
shape'
,
'
polys'
,
'
ignore_tags'
]
loader
:
shuffle
:
False
drop_last
:
False
batch_size_per_card
:
1
# must be 1
num_workers
:
0
use_shared_memory
:
False
test_tipc/configs/ch_ppocr_mobile_v2.0_det/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
View file @
2b3f89f0
===========================train_params===========================
===========================train_params===========================
model_name:
ocr
_det
model_name:
ch_ppocr_mobile_v2.0
_det
python:python3.7
python:python3.7
gpu_list:0|0,1
gpu_list:0|0,1
Global.use_gpu:True|True
Global.use_gpu:True|True
Global.auto_cast:amp
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=300
Global.epoch_num:lite_train_lite_infer=1
00
|whole_train_whole_infer=300
Global.save_model_dir:./output/
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4
Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4
Global.pretrained_model:null
Global.pretrained_model:null
...
@@ -12,10 +12,10 @@ train_model_name:latest
...
@@ -12,10 +12,10 @@ train_model_name:latest
train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/
train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/
null:null
null:null
##
##
trainer:norm_train
|pact_train|fpgm_train
trainer:norm_train
norm_train:tools/train.py -c
test_tipc/configs/ppocr_det_mobile/
det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained
norm_train:tools/train.py -c
configs/det/ch_ppocr_v2.0/ch_
det_mv3_db
_v2.0
.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained
pact_train:
deploy/slim/quantization/quant.py -c test_tipc/configs/ppocr_det_mobile/det_mv3_db.yml -o
pact_train:
null
fpgm_train:
deploy/slim/prune/sensitivity_anal.py -c test_tipc/configs/ppocr_det_mobile/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy
fpgm_train:
null
distill_train:null
distill_train:null
null:null
null:null
null:null
null:null
...
@@ -26,10 +26,10 @@ null:null
...
@@ -26,10 +26,10 @@ null:null
##
##
===========================infer_params===========================
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.save_inference_dir:./output/
Global.
pretrained_model
:
Global.
checkpoints
:
norm_export:tools/export_model.py -c
test_tipc/configs/ppocr_det_mobile/
det_mv3_db.yml -o
norm_export:tools/export_model.py -c
configs/det/ch_ppocr_v2.0/ch_
det_mv3_db
_v2.0
.yml -o
quant_export:
deploy/slim/quantization/export_model.py -c test_tipc/configs/ppocr_det_mobile/det_mv3_db.yml -o
quant_export:
null
fpgm_export:
deploy/slim/prune/export_prune_model.py -c test_tipc/configs/ppocr_det_mobile/det_mv3_db.yml -o
fpgm_export:
null
distill_export:null
distill_export:null
export1:null
export1:null
export2:null
export2:null
...
@@ -49,3 +49,5 @@ inference:tools/infer/predict_det.py
...
@@ -49,3 +49,5 @@ inference:tools/infer/predict_det.py
null:null
null:null
--benchmark:True
--benchmark:True
null:null
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,640,640]}];[{float32,[3,960,960]}]
\ No newline at end of file
test_tipc/configs/ch_ppocr_mobile_
V
2.0_det_FPGM/train_infer_python.txt
→
test_tipc/configs/ch_ppocr_mobile_
v
2.0_det_FPGM/train_infer_python.txt
View file @
2b3f89f0
===========================train_params===========================
===========================train_params===========================
model_name:
ocr_det
model_name:
ch_ppocr_mobile_v2.0_det_FPGM
python:python3.7
python:python3.7
gpu_list:0|0,1
gpu_list:0|0,1
Global.use_gpu:True|True
Global.use_gpu:True|True
...
...
test_tipc/configs/ch_ppocr_mobile_v2.0_det_FPGM/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_mobile_v2.0_det_FPGM
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=5|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/
null:null
##
trainer:fpgm_train
norm_train:null
pact_train:null
fpgm_train:deploy/slim/prune/sensitivity_anal.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:null
quant_export:null
fpgm_export:deploy/slim/prune/export_prune_model.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -o
distill_export:null
export1:null
export2:null
inference_dir:null
train_model:null
infer_export:null
infer_quant:False
inference:tools/infer/predict_det.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1
--use_tensorrt:False|True
--precision:fp32|fp16|int8
--det_model_dir:
--image_dir:./inference/ch_det_data_50/all-sum-510/
null:null
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,640,640]}];[{float32,[3,960,960]}]
\ No newline at end of file
test_tipc/configs/ch_ppocr_mobile_v2.0_det_PACT/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_mobile_v2.0_det_PACT
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=20|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/
null:null
##
trainer:pact_train
norm_train:null
pact_train:deploy/slim/quantization/quant.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -o
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:null
quant_export:deploy/slim/quantization/export_model.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -o
fpgm_export:null
distill_export:null
export1:null
export2:null
inference_dir:null
train_model:./inference/ch_ppocr_mobile_v2.0_det_prune_infer/
infer_export:null
infer_quant:False
inference:tools/infer/predict_det.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1
--use_tensorrt:False|True
--precision:fp32|fp16|int8
--det_model_dir:
--image_dir:./inference/ch_det_data_50/all-sum-510/
null:null
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,640,640]}];[{float32,[3,960,960]}]
test_tipc/configs/ch_ppocr_mobile_v2.0_rec/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_mobile_v2.0_rec
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=2|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=128|whole_train_whole_infer=128
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./inference/rec_inference
null:null
##
trainer:norm_train
norm_train:tools/train.py -c configs/rec/rec_icdar15_train.yml -o
pact_train:null
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:tools/eval.py -c configs/rec/rec_icdar15_train.yml -o
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:tools/export_model.py -c configs/rec/rec_icdar15_train.yml -o
quant_export:null
fpgm_export:null
distill_export:null
export1:null
export2:null
##
train_model:./inference/ch_ppocr_mobile_v2.0_rec_train/best_accuracy
infer_export:tools/export_model.py -c configs/rec/rec_icdar15_train.yml -o
infer_quant:False
inference:tools/infer/predict_rec.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1|6
--use_tensorrt:True|False
--precision:fp32|int8
--rec_model_dir:
--image_dir:./inference/rec_inference
--save_log_path:./test/output/
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,32,100]}]
test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_mobile_v2.0_rec_FPGM
python:python3.7
gpu_list:0
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=128|whole_train_whole_infer=128
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./train_data/ic15_data/test/word_1.png
null:null
##
trainer:fpgm_train
norm_train:null
pact_train:null
fpgm_train:deploy/slim/prune/sensitivity_anal.py -c test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/rec_chinese_lite_train_v2.0.yml -o Global.pretrained_model=./pretrain_models/ch_ppocr_mobile_v2.0_rec_train/best_accuracy
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:null
quant_export:null
fpgm_export:deploy/slim/prune/export_prune_model.py -c test_tipc/configs/ch_ppocr_mobile_v2.0_rec_FPGM/rec_chinese_lite_train_v2.0.yml -o
distill_export:null
export1:null
export2:null
inference_dir:null
train_model:null
infer_export:null
infer_quant:False
inference:tools/infer/predict_rec.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1
--use_tensorrt:False|True
--precision:fp32|int8
--rec_model_dir:
--image_dir:./inference/rec_inference
null:null
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,32,320]}]
\ No newline at end of file
test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_mobile_v2.0_rec_PACT
python:python3.7
gpu_list:0
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=128|whole_train_whole_infer=128
Global.checkpoints:null
train_model_name:latest
train_infer_img_dir:./train_data/ic15_data/test/word_1.png
null:null
##
trainer:pact_train
norm_train:null
pact_train:deploy/slim/quantization/quant.py -c test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/rec_chinese_lite_train_v2.0.yml -o
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:null
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:null
quant_export:deploy/slim/quantization/export_model.py -c test_tipc/configs/ch_ppocr_mobile_v2.0_rec_PACT/rec_chinese_lite_train_v2.0.yml -o
fpgm_export:null
distill_export:null
export1:null
export2:null
inference_dir:null
infer_model:./inference/ch_ppocr_mobile_v2.0_rec_slim_infer/
infer_export:null
infer_quant:False
inference:tools/infer/predict_rec.py --rec_char_dict_path=./ppocr/utils/ppocr_keys_v1.txt --rec_image_shape="3,32,100"
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1|6
--use_tensorrt:False|True
--precision:fp32|int8
--rec_model_dir:
--image_dir:./inference/rec_inference
--save_log_path:./test/output/
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,32,320]}]
test_tipc/configs/ch_ppocr_server_v2.0_det/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_server_v2.0_det
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=2|whole_train_whole_infer=300
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_lite_infer=4
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/
null:null
##
trainer:norm_train
norm_train:tools/train.py -c test_tipc/configs/ch_ppocr_server_v2.0_det/det_r50_vd_db.yml -o
quant_train:null
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:tools/eval.py -c test_tipc/configs/ch_ppocr_server_v2.0_det/det_r50_vd_db.yml -o
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:tools/export_model.py -c test_tipc/configs/ch_ppocr_server_v2.0_det/det_r50_vd_db.yml -o
quant_export:null
fpgm_export:null
distill_export:null
export1:null
export2:null
##
train_model:./inference/ch_ppocr_server_v2.0_det_train/best_accuracy
infer_export:tools/export_model.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml -o
infer_quant:False
inference:tools/infer/predict_det.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1
--use_tensorrt:False|True
--precision:fp32|fp16|int8
--det_model_dir:
--image_dir:./inference/ch_det_data_50/all-sum-510/
--save_log_path:null
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,640,640]}];[{float32,[3,960,960]}]
\ No newline at end of file
test_tipc/configs/ch_ppocr_server_v2.0_rec/train_linux_gpu_normal_amp_infer_python_linux_gpu_cpu.txt
0 → 100644
View file @
2b3f89f0
===========================train_params===========================
model_name:ch_ppocr_server_v2.0_rec
python:python3.7
gpu_list:0|0,1
Global.use_gpu:True|True
Global.auto_cast:amp
Global.epoch_num:lite_train_lite_infer=5|whole_train_whole_infer=100
Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=128|whole_train_whole_infer=128
Global.pretrained_model:null
train_model_name:latest
train_infer_img_dir:./inference/rec_inference
null:null
##
trainer:norm_train
norm_train:tools/train.py -c test_tipc/configs/ch_ppocr_server_v2.0_rec/rec_icdar15_train.yml -o
pact_train:null
fpgm_train:null
distill_train:null
null:null
null:null
##
===========================eval_params===========================
eval:tools/eval.py -c test_tipc/configs/ch_ppocr_server_v2.0_rec/rec_icdar15_train.yml -o
null:null
##
===========================infer_params===========================
Global.save_inference_dir:./output/
Global.checkpoints:
norm_export:tools/export_model.py -c test_tipc/configs/ch_ppocr_server_v2.0_rec/rec_icdar15_train.yml -o
quant_export:null
fpgm_export:null
distill_export:null
export1:null
export2:null
##
train_model:./inference/ch_ppocr_server_v2.0_rec_train/best_accuracy
infer_export:tools/export_model.py -c test_tipc/configs/ch_ppocr_server_v2.0_rec/rec_icdar15_train.yml -o
infer_quant:False
inference:tools/infer/predict_rec.py
--use_gpu:True|False
--enable_mkldnn:True|False
--cpu_threads:1|6
--rec_batch_num:1|6
--use_tensorrt:True|False
--precision:fp32|int8
--rec_model_dir:
--image_dir:./inference/rec_inference
--save_log_path:./test/output/
--benchmark:True
null:null
===========================infer_benchmark_params==========================
random_infer_input:[{float32,[3,32,100]}]
tools/eval.py
View file @
2b3f89f0
...
@@ -47,14 +47,40 @@ def main():
...
@@ -47,14 +47,40 @@ def main():
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
]:
# distillation model
]:
# distillation model
for
key
in
config
[
'Architecture'
][
"Models"
]:
for
key
in
config
[
'Architecture'
][
"Models"
]:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
if
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels'
]
=
char_num
'name'
]
==
'MultiHead'
:
# for multi head
out_channels_list
=
{}
if
config
[
'PostProcess'
][
'name'
]
==
'DistillationSARLabelDecode'
:
char_num
=
char_num
-
2
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
'out_channels'
]
=
char_num
elif
config
[
'Architecture'
][
'Head'
][
'name'
]
==
'MultiHead'
:
# for multi head
out_channels_list
=
{}
if
config
[
'PostProcess'
][
'name'
]
==
'SARLabelDecode'
:
char_num
=
char_num
-
2
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
# base rec model
else
:
# base rec model
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
model
=
build_model
(
config
[
'Architecture'
])
model
=
build_model
(
config
[
'Architecture'
])
extra_input
=
config
[
'Architecture'
][
extra_input_models
=
[
"SRN"
,
"NRTR"
,
"SAR"
,
"SEED"
,
"SVTR"
]
'algorithm'
]
in
[
"SRN"
,
"NRTR"
,
"SAR"
,
"SEED"
]
extra_input
=
False
if
config
[
'Architecture'
][
'algorithm'
]
==
'Distillation'
:
for
key
in
config
[
'Architecture'
][
"Models"
]:
extra_input
=
extra_input
or
config
[
'Architecture'
][
'Models'
][
key
][
'algorithm'
]
in
extra_input_models
else
:
extra_input
=
config
[
'Architecture'
][
'algorithm'
]
in
extra_input_models
if
"model_type"
in
config
[
'Architecture'
].
keys
():
if
"model_type"
in
config
[
'Architecture'
].
keys
():
model_type
=
config
[
'Architecture'
][
'model_type'
]
model_type
=
config
[
'Architecture'
][
'model_type'
]
else
:
else
:
...
...
tools/export_model.py
View file @
2b3f89f0
...
@@ -55,6 +55,18 @@ def export_single_model(model, arch_config, save_path, logger):
...
@@ -55,6 +55,18 @@ def export_single_model(model, arch_config, save_path, logger):
shape
=
[
None
,
3
,
48
,
160
],
dtype
=
"float32"
),
shape
=
[
None
,
3
,
48
,
160
],
dtype
=
"float32"
),
]
]
model
=
to_static
(
model
,
input_spec
=
other_shape
)
model
=
to_static
(
model
,
input_spec
=
other_shape
)
elif
arch_config
[
"algorithm"
]
==
"SVTR"
:
if
arch_config
[
"Head"
][
"name"
]
==
'MultiHead'
:
other_shape
=
[
paddle
.
static
.
InputSpec
(
shape
=
[
None
,
3
,
48
,
-
1
],
dtype
=
"float32"
),
]
else
:
other_shape
=
[
paddle
.
static
.
InputSpec
(
shape
=
[
None
,
3
,
64
,
256
],
dtype
=
"float32"
),
]
model
=
to_static
(
model
,
input_spec
=
other_shape
)
elif
arch_config
[
"algorithm"
]
==
"PREN"
:
elif
arch_config
[
"algorithm"
]
==
"PREN"
:
other_shape
=
[
other_shape
=
[
paddle
.
static
.
InputSpec
(
paddle
.
static
.
InputSpec
(
...
@@ -105,13 +117,36 @@ def main():
...
@@ -105,13 +117,36 @@ def main():
if
config
[
"Architecture"
][
"algorithm"
]
in
[
"Distillation"
,
if
config
[
"Architecture"
][
"algorithm"
]
in
[
"Distillation"
,
]:
# distillation model
]:
# distillation model
for
key
in
config
[
"Architecture"
][
"Models"
]:
for
key
in
config
[
"Architecture"
][
"Models"
]:
config
[
"Architecture"
][
"Models"
][
key
][
"Head"
][
if
config
[
"Architecture"
][
"Models"
][
key
][
"Head"
][
"out_channels"
]
=
char_num
"name"
]
==
'MultiHead'
:
# multi head
out_channels_list
=
{}
if
config
[
'PostProcess'
][
'name'
]
==
'DistillationSARLabelDecode'
:
char_num
=
char_num
-
2
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
loss_list
=
config
[
'Loss'
][
'loss_config_list'
]
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
config
[
"Architecture"
][
"Models"
][
key
][
"Head"
][
"out_channels"
]
=
char_num
# just one final tensor needs to to exported for inference
# just one final tensor needs to to exported for inference
config
[
"Architecture"
][
"Models"
][
key
][
config
[
"Architecture"
][
"Models"
][
key
][
"return_all_feats"
]
=
False
"return_all_feats"
]
=
False
elif
config
[
'Architecture'
][
'Head'
][
'name'
]
==
'MultiHead'
:
# multi head
out_channels_list
=
{}
char_num
=
len
(
getattr
(
post_process_class
,
'character'
))
if
config
[
'PostProcess'
][
'name'
]
==
'SARLabelDecode'
:
char_num
=
char_num
-
2
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
# base rec model
else
:
# base rec model
config
[
"Architecture"
][
"Head"
][
"out_channels"
]
=
char_num
config
[
"Architecture"
][
"Head"
][
"out_channels"
]
=
char_num
model
=
build_model
(
config
[
"Architecture"
])
model
=
build_model
(
config
[
"Architecture"
])
load_model
(
config
,
model
)
load_model
(
config
,
model
)
model
.
eval
()
model
.
eval
()
...
...
tools/infer/predict_rec.py
View file @
2b3f89f0
...
@@ -107,7 +107,7 @@ class TextRecognizer(object):
...
@@ -107,7 +107,7 @@ class TextRecognizer(object):
return
norm_img
.
astype
(
np
.
float32
)
/
128.
-
1.
return
norm_img
.
astype
(
np
.
float32
)
/
128.
-
1.
assert
imgC
==
img
.
shape
[
2
]
assert
imgC
==
img
.
shape
[
2
]
imgW
=
int
((
32
*
max_wh_ratio
))
imgW
=
int
((
imgH
*
max_wh_ratio
))
if
self
.
use_onnx
:
if
self
.
use_onnx
:
w
=
self
.
input_tensor
.
shape
[
3
:][
0
]
w
=
self
.
input_tensor
.
shape
[
3
:][
0
]
if
w
is
not
None
and
w
>
0
:
if
w
is
not
None
and
w
>
0
:
...
@@ -131,6 +131,17 @@ class TextRecognizer(object):
...
@@ -131,6 +131,17 @@ class TextRecognizer(object):
padding_im
=
np
.
zeros
((
imgC
,
imgH
,
imgW
),
dtype
=
np
.
float32
)
padding_im
=
np
.
zeros
((
imgC
,
imgH
,
imgW
),
dtype
=
np
.
float32
)
padding_im
[:,
:,
0
:
resized_w
]
=
resized_image
padding_im
[:,
:,
0
:
resized_w
]
=
resized_image
return
padding_im
return
padding_im
def
resize_norm_img_svtr
(
self
,
img
,
image_shape
):
imgC
,
imgH
,
imgW
=
image_shape
resized_image
=
cv2
.
resize
(
img
,
(
imgW
,
imgH
),
interpolation
=
cv2
.
INTER_LINEAR
)
resized_image
=
resized_image
.
astype
(
'float32'
)
resized_image
=
resized_image
.
transpose
((
2
,
0
,
1
))
/
255
resized_image
-=
0.5
resized_image
/=
0.5
return
resized_image
def
resize_norm_img_srn
(
self
,
img
,
image_shape
):
def
resize_norm_img_srn
(
self
,
img
,
image_shape
):
imgC
,
imgH
,
imgW
=
image_shape
imgC
,
imgH
,
imgW
=
image_shape
...
@@ -255,18 +266,16 @@ class TextRecognizer(object):
...
@@ -255,18 +266,16 @@ class TextRecognizer(object):
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
=
[]
max_wh_ratio
=
0
imgC
,
imgH
,
imgW
=
self
.
rec_image_shape
max_wh_ratio
=
imgW
/
imgH
# max_wh_ratio = 0
for
ino
in
range
(
beg_img_no
,
end_img_no
):
for
ino
in
range
(
beg_img_no
,
end_img_no
):
h
,
w
=
img_list
[
indices
[
ino
]].
shape
[
0
:
2
]
h
,
w
=
img_list
[
indices
[
ino
]].
shape
[
0
:
2
]
wh_ratio
=
w
*
1.0
/
h
wh_ratio
=
w
*
1.0
/
h
max_wh_ratio
=
max
(
max_wh_ratio
,
wh_ratio
)
max_wh_ratio
=
max
(
max_wh_ratio
,
wh_ratio
)
for
ino
in
range
(
beg_img_no
,
end_img_no
):
for
ino
in
range
(
beg_img_no
,
end_img_no
):
if
self
.
rec_algorithm
!=
"SRN"
and
self
.
rec_algorithm
!=
"SAR"
:
norm_img
=
self
.
resize_norm_img
(
img_list
[
indices
[
ino
]],
if
self
.
rec_algorithm
==
"SAR"
:
max_wh_ratio
)
norm_img
=
norm_img
[
np
.
newaxis
,
:]
norm_img_batch
.
append
(
norm_img
)
elif
self
.
rec_algorithm
==
"SAR"
:
norm_img
,
_
,
_
,
valid_ratio
=
self
.
resize_norm_img_sar
(
norm_img
,
_
,
_
,
valid_ratio
=
self
.
resize_norm_img_sar
(
img_list
[
indices
[
ino
]],
self
.
rec_image_shape
)
img_list
[
indices
[
ino
]],
self
.
rec_image_shape
)
norm_img
=
norm_img
[
np
.
newaxis
,
:]
norm_img
=
norm_img
[
np
.
newaxis
,
:]
...
@@ -274,7 +283,7 @@ class TextRecognizer(object):
...
@@ -274,7 +283,7 @@ class TextRecognizer(object):
valid_ratios
=
[]
valid_ratios
=
[]
valid_ratios
.
append
(
valid_ratio
)
valid_ratios
.
append
(
valid_ratio
)
norm_img_batch
.
append
(
norm_img
)
norm_img_batch
.
append
(
norm_img
)
el
se
:
el
if
self
.
rec_algorithm
==
"SRN"
:
norm_img
=
self
.
process_image_srn
(
norm_img
=
self
.
process_image_srn
(
img_list
[
indices
[
ino
]],
self
.
rec_image_shape
,
8
,
25
)
img_list
[
indices
[
ino
]],
self
.
rec_image_shape
,
8
,
25
)
encoder_word_pos_list
=
[]
encoder_word_pos_list
=
[]
...
@@ -286,6 +295,16 @@ class TextRecognizer(object):
...
@@ -286,6 +295,16 @@ class TextRecognizer(object):
gsrm_slf_attn_bias1_list
.
append
(
norm_img
[
3
])
gsrm_slf_attn_bias1_list
.
append
(
norm_img
[
3
])
gsrm_slf_attn_bias2_list
.
append
(
norm_img
[
4
])
gsrm_slf_attn_bias2_list
.
append
(
norm_img
[
4
])
norm_img_batch
.
append
(
norm_img
[
0
])
norm_img_batch
.
append
(
norm_img
[
0
])
elif
self
.
rec_algorithm
==
"SVTR"
:
norm_img
=
self
.
resize_norm_img_svtr
(
img_list
[
indices
[
ino
]],
self
.
rec_image_shape
)
norm_img
=
norm_img
[
np
.
newaxis
,
:]
norm_img_batch
.
append
(
norm_img
)
else
:
norm_img
=
self
.
resize_norm_img
(
img_list
[
indices
[
ino
]],
max_wh_ratio
)
norm_img
=
norm_img
[
np
.
newaxis
,
:]
norm_img_batch
.
append
(
norm_img
)
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
:
if
self
.
benchmark
:
...
...
tools/infer/utility.py
View file @
2b3f89f0
...
@@ -271,9 +271,10 @@ def create_predictor(args, mode, logger):
...
@@ -271,9 +271,10 @@ def create_predictor(args, mode, logger):
elif
mode
==
"rec"
:
elif
mode
==
"rec"
:
if
args
.
rec_algorithm
!=
"CRNN"
:
if
args
.
rec_algorithm
!=
"CRNN"
:
use_dynamic_shape
=
False
use_dynamic_shape
=
False
min_input_shape
=
{
"x"
:
[
1
,
3
,
32
,
10
]}
imgH
=
int
(
args
.
rec_image_shape
.
split
(
','
)[
-
2
])
max_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
32
,
1536
]}
min_input_shape
=
{
"x"
:
[
1
,
3
,
imgH
,
10
]}
opt_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
32
,
320
]}
max_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
imgH
,
1536
]}
opt_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
imgH
,
320
]}
elif
mode
==
"cls"
:
elif
mode
==
"cls"
:
min_input_shape
=
{
"x"
:
[
1
,
3
,
48
,
10
]}
min_input_shape
=
{
"x"
:
[
1
,
3
,
48
,
10
]}
max_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
48
,
1024
]}
max_input_shape
=
{
"x"
:
[
args
.
rec_batch_num
,
3
,
48
,
1024
]}
...
@@ -300,7 +301,8 @@ def create_predictor(args, mode, logger):
...
@@ -300,7 +301,8 @@ def create_predictor(args, mode, logger):
# enable memory optim
# enable memory optim
config
.
enable_memory_optim
()
config
.
enable_memory_optim
()
config
.
disable_glog_info
()
config
.
disable_glog_info
()
config
.
delete_pass
(
"reshape_transpose_matmul_v2_mkldnn_fuse_pass"
)
config
.
delete_pass
(
"reshape_transpose_matmul_mkldnn_fuse_pass"
)
config
.
delete_pass
(
"conv_transpose_eltwiseadd_bn_fuse_pass"
)
config
.
delete_pass
(
"conv_transpose_eltwiseadd_bn_fuse_pass"
)
if
mode
==
'table'
:
if
mode
==
'table'
:
config
.
delete_pass
(
"fc_fuse_pass"
)
# not supported for table
config
.
delete_pass
(
"fc_fuse_pass"
)
# not supported for table
...
...
tools/infer_rec.py
View file @
2b3f89f0
...
@@ -51,8 +51,28 @@ def main():
...
@@ -51,8 +51,28 @@ def main():
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
]:
# distillation model
]:
# distillation model
for
key
in
config
[
'Architecture'
][
"Models"
]:
for
key
in
config
[
'Architecture'
][
"Models"
]:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
if
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels'
]
=
char_num
'name'
]
==
'MultiHead'
:
# for multi head
out_channels_list
=
{}
if
config
[
'PostProcess'
][
'name'
]
==
'DistillationSARLabelDecode'
:
char_num
=
char_num
-
2
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
'out_channels'
]
=
char_num
elif
config
[
'Architecture'
][
'Head'
][
'name'
]
==
'MultiHead'
:
# for multi head loss
out_channels_list
=
{}
if
config
[
'PostProcess'
][
'name'
]
==
'SARLabelDecode'
:
char_num
=
char_num
-
2
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
# base rec model
else
:
# base rec model
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
...
...
tools/program.py
View file @
2b3f89f0
...
@@ -201,12 +201,19 @@ def train(config,
...
@@ -201,12 +201,19 @@ def train(config,
model
.
train
()
model
.
train
()
use_srn
=
config
[
'Architecture'
][
'algorithm'
]
==
"SRN"
use_srn
=
config
[
'Architecture'
][
'algorithm'
]
==
"SRN"
extra_input
=
config
[
'Architecture'
][
extra_input_models
=
[
"SRN"
,
"NRTR"
,
"SAR"
,
"SEED"
,
"SVTR"
]
'algorithm'
]
in
[
"SRN"
,
"NRTR"
,
"SAR"
,
"SEED"
]
extra_input
=
False
if
config
[
'Architecture'
][
'algorithm'
]
==
'Distillation'
:
for
key
in
config
[
'Architecture'
][
"Models"
]:
extra_input
=
extra_input
or
config
[
'Architecture'
][
'Models'
][
key
][
'algorithm'
]
in
extra_input_models
else
:
extra_input
=
config
[
'Architecture'
][
'algorithm'
]
in
extra_input_models
try
:
try
:
model_type
=
config
[
'Architecture'
][
'model_type'
]
model_type
=
config
[
'Architecture'
][
'model_type'
]
except
:
except
:
model_type
=
None
model_type
=
None
algorithm
=
config
[
'Architecture'
][
'algorithm'
]
algorithm
=
config
[
'Architecture'
][
'algorithm'
]
start_epoch
=
best_model_dict
[
start_epoch
=
best_model_dict
[
...
@@ -269,7 +276,12 @@ def train(config,
...
@@ -269,7 +276,12 @@ def train(config,
if
model_type
in
[
'table'
,
'kie'
]:
if
model_type
in
[
'table'
,
'kie'
]:
eval_class
(
preds
,
batch
)
eval_class
(
preds
,
batch
)
else
:
else
:
post_result
=
post_process_class
(
preds
,
batch
[
1
])
if
config
[
'Loss'
][
'name'
]
in
[
'MultiLoss'
,
'MultiLoss_v2'
]:
# for multi head loss
post_result
=
post_process_class
(
preds
[
'ctc'
],
batch
[
1
])
# for CTC head out
else
:
post_result
=
post_process_class
(
preds
,
batch
[
1
])
eval_class
(
post_result
,
batch
)
eval_class
(
post_result
,
batch
)
metric
=
eval_class
.
get_metric
()
metric
=
eval_class
.
get_metric
()
train_stats
.
update
(
metric
)
train_stats
.
update
(
metric
)
...
@@ -541,7 +553,7 @@ def preprocess(is_train=False):
...
@@ -541,7 +553,7 @@ def preprocess(is_train=False):
assert
alg
in
[
assert
alg
in
[
'EAST'
,
'DB'
,
'SAST'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
,
'SRN'
,
'EAST'
,
'DB'
,
'SAST'
,
'Rosetta'
,
'CRNN'
,
'STARNet'
,
'RARE'
,
'SRN'
,
'CLS'
,
'PGNet'
,
'Distillation'
,
'NRTR'
,
'TableAttn'
,
'SAR'
,
'PSE'
,
'CLS'
,
'PGNet'
,
'Distillation'
,
'NRTR'
,
'TableAttn'
,
'SAR'
,
'PSE'
,
'SEED'
,
'SDMGR'
,
'LayoutXLM'
,
'LayoutLM'
,
'PREN'
,
'FCE'
'SEED'
,
'SDMGR'
,
'LayoutXLM'
,
'LayoutLM'
,
'PREN'
,
'FCE'
,
'SVTR'
]
]
device
=
'cpu'
device
=
'cpu'
...
...
tools/train.py
View file @
2b3f89f0
...
@@ -74,11 +74,49 @@ def main(config, device, logger, vdl_writer):
...
@@ -74,11 +74,49 @@ def main(config, device, logger, vdl_writer):
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
if
config
[
'Architecture'
][
"algorithm"
]
in
[
"Distillation"
,
]:
# distillation model
]:
# distillation model
for
key
in
config
[
'Architecture'
][
"Models"
]:
for
key
in
config
[
'Architecture'
][
"Models"
]:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
if
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels'
]
=
char_num
'name'
]
==
'MultiHead'
:
# for multi head
if
config
[
'PostProcess'
][
'name'
]
==
'DistillationSARLabelDecode'
:
char_num
=
char_num
-
2
# update SARLoss params
assert
list
(
config
[
'Loss'
][
'loss_config_list'
][
-
1
].
keys
())[
0
]
==
'DistillationSARLoss'
config
[
'Loss'
][
'loss_config_list'
][
-
1
][
'DistillationSARLoss'
][
'ignore_index'
]
=
char_num
+
1
out_channels_list
=
{}
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Models'
][
key
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
config
[
'Architecture'
][
"Models"
][
key
][
"Head"
][
'out_channels'
]
=
char_num
elif
config
[
'Architecture'
][
'Head'
][
'name'
]
==
'MultiHead'
:
# for multi head
if
config
[
'PostProcess'
][
'name'
]
==
'SARLabelDecode'
:
char_num
=
char_num
-
2
# update SARLoss params
assert
list
(
config
[
'Loss'
][
'loss_config_list'
][
1
].
keys
())[
0
]
==
'SARLoss'
if
config
[
'Loss'
][
'loss_config_list'
][
1
][
'SARLoss'
]
is
None
:
config
[
'Loss'
][
'loss_config_list'
][
1
][
'SARLoss'
]
=
{
'ignore_index'
:
char_num
+
1
}
else
:
config
[
'Loss'
][
'loss_config_list'
][
1
][
'SARLoss'
][
'ignore_index'
]
=
char_num
+
1
out_channels_list
=
{}
out_channels_list
[
'CTCLabelDecode'
]
=
char_num
out_channels_list
[
'SARLabelDecode'
]
=
char_num
+
2
config
[
'Architecture'
][
'Head'
][
'out_channels_list'
]
=
out_channels_list
else
:
# base rec model
else
:
# base rec model
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
config
[
'Architecture'
][
"Head"
][
'out_channels'
]
=
char_num
if
config
[
'PostProcess'
][
'name'
]
==
'SARLabelDecode'
:
# for SAR model
config
[
'Loss'
][
'ignore_index'
]
=
char_num
-
1
model
=
build_model
(
config
[
'Architecture'
])
model
=
build_model
(
config
[
'Architecture'
])
if
config
[
'Global'
][
'distributed'
]:
if
config
[
'Global'
][
'distributed'
]:
model
=
paddle
.
DataParallel
(
model
)
model
=
paddle
.
DataParallel
(
model
)
...
@@ -91,7 +129,7 @@ def main(config, device, logger, vdl_writer):
...
@@ -91,7 +129,7 @@ def main(config, device, logger, vdl_writer):
config
[
'Optimizer'
],
config
[
'Optimizer'
],
epochs
=
config
[
'Global'
][
'epoch_num'
],
epochs
=
config
[
'Global'
][
'epoch_num'
],
step_each_epoch
=
len
(
train_dataloader
),
step_each_epoch
=
len
(
train_dataloader
),
parameters
=
model
.
parameters
()
)
model
=
model
)
# build metric
# build metric
eval_class
=
build_metric
(
config
[
'Metric'
])
eval_class
=
build_metric
(
config
[
'Metric'
])
...
...
Prev
1
2
3
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