training text detection
Download the pre-training model and put it under pretrain_models and decompress it to find the configuration file corresponding to the pre-training model, for example: configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml. Modify the path of Train and val:
Global:
use_gpu: true
epoch_num: 1200
log_smooth_window: 20
print_batch_step: 2
save_model_dir: ./output/ch_db_res18/
save_epoch_step: 1200
# evaluation is run every 5000 iterations after the 4000th iteration
eval_batch_step: [0, 10]
Train:
dataset:
name: SimpleDataSet
data_dir: /home/data/det_data/
label_file_list:
- /home/data/det_data/det_train_label.txt
Eval:
dataset:
name: SimpleDataSet
data_dir: /home/data/det_data/
label_file_list:
- /home/data/det_data/det_val_label.txt
Start training:
python tools/train.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml -o Global.pretrained_model=pretrain_models/ch_ppocr_server_v2.0_det_train/best_accuracy \
Global.epoch_num=50 Global.save_epoch_step=20 Global.save_model_dir=output/det/ Train.loader.batch_size_per_card=8 Train.loader.num_workers=2
# 断点重开
python tools/train.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml -o Global.checkpoints=output/det/latest.pdparams \
Global.epoch_num=50 Global.save_epoch_step=20 Global.save_model_dir=output/det/ Train.loader.batch_size_per_card=8 Train.loader.num_workers=2
Models are stored under output/det/:
Transfer to inference model:
python tools/export_model.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml -o Global.pretrained_model=output/det/best_accuracy Global.save_inference_dir=inference/det/
Models are stored under inference/det/:
Transfer to onnx model:
paddle2onnx --model_dir inference/det/ --model_filename inference.pdmodel --params_filename inference.pdiparams \
--save_file onnx_model/det.onnx --opset_version 10 --input_shape_dict="{'x':[-1,3,-1,-1]}" --enable_onnx_checker True
Models are stored under onnx_model
Train an Orientation Classifier
Download the pre-training model and put it under pretrain_models and decompress it to find the configuration file corresponding to the pre-training model, for example: configs/cls/cls_mv3.yml. Modify the path of Train and val:
Global:
use_gpu: true
epoch_num: 100
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/cls/mv3/
save_epoch_step: 3
# evaluation is run every 5000 iterations after the 4000th iteration
eval_batch_step: [0, 10]
Train:
dataset:
name: SimpleDataSet
data_dir: /home/data/cls_data/
label_file_list:
- /home/data/cls_data/cls_train_label.txt
Eval:
dataset:
name: SimpleDataSet
data_dir: /home/data/cls_data/
label_file_list:
- /home/data/cls_data/cls_val_label.txt
Start training:
python tools/train.py -c configs/cls/cls_mv3.yml -o Global.pretrained_model=pretrain_models/ch_ppocr_mobile_v2.0_cls_train/best_accuracy \
Global.epoch_num=50 Global.save_epoch_step=20 Global.save_model_dir=output/cls/ Train.loader.batch_size_per_card=8 Train.loader.num_workers=2
Models are stored under output/cls/:
Transfer to inference model:
python tools/export_model.py -c configs/cls/cls_mv3.yml -o Global.pretrained_model=output/cls/best_accuracy Global.save_inference_dir=inference/cls/
Models are stored under inference/det/:
Transfer to onnx model:
paddle2onnx --model_dir inference/cls/ --model_filename inference.pdmodel --params_filename inference.pdiparams \
--save_file onnx_model/cls.onnx --opset_version 10 --input_shape_dict="{'x':[-1,3,-1,-1]}" --enable_onnx_checker True
Models are stored under onnx_model
training text recognition
Download the pre-training model and put it under pretrain_models and decompress it to find the configuration file corresponding to the pre-training model, for example: configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml. Modify the path of Train and val, as well as the path of the dictionary (here the dictionary uses the default)
Global:
use_gpu: true
epoch_num: 500
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/rec_chinese_common_v2.0
save_epoch_step: 3
# evaluation is run every 5000 iterations after the 4000th iteration
eval_batch_step: [0, 10]
Train:
dataset:
name: SimpleDataSet
data_dir: /home/data/res_data/
label_file_list: ["/home/data/res_data/res_train_label.txt"]
Eval:
dataset:
name: SimpleDataSet
data_dir: /home/data/res_data/
label_file_list: ["/home/data/res_data/res_val_label.txt"]
Start training:
python tools/train.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml -o Global.pretrained_model=pretrain_models/ch_ppocr_server_v2.0_rec_train/best_accuracy \
Global.character_dict_path=ppocr/utils/ppocr_keys_v1.txt Global.epoch_num=50 Global.save_epoch_step=20 Global.save_model_dir=output/rec/ \
Train.loader.batch_size_per_card=8 Train.loader.num_workers=2
Models are stored under output/rec/:
Transfer to inference model:
python tools/export_model.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml -o Global.pretrained_model=output/rec/best_accuracy \
Global.save_inference_dir=inference/rec/ Global.character_dict_path=ppocr/utils/ppocr_keys_v1.txt
Models are stored under inference/rec/:
Transfer to onnx model:
paddle2onnx --model_dir inference/rec/ --model_filename inference.pdmodel --params_filename inference.pdiparams \
--save_file onnx_model/rec.onnx --opset_version 10 --input_shape_dict="{'x':[-1,3,-1,-1]}" --enable_onnx_checker True
Models are stored under onnx_model
model reasoning
Use the trained inference model for inference:
python tools/infer/predict_system.py --image_dir doc/imgs/00111002.jpg \
--det_model_dir inference/det/ \
--rec_model_dir inference/rec/ \
--cls_model_dir inference/cls/ \
--use_angle_cls True \
--use_space_char True
Use the trained onnx for inference:
You can modify the input_size of the onnx model as needed, and put the modified model under onnx_inference:
python tools/infer/predict_system.py --use_gpu=False --use_onnx=True \
--det_model_dir=onnx_inference/det.onnx \
--rec_model_dir=onnx_inference/rec.onnx \
--cls_model_dir=onnx_inference/cls.onnx \
--image_dir=doc/imgs/00111002.jpg \
--rec_char_dict_path=ppocr/utils/ppocr_keys_v1.txt