From 95567abe45e0d69312ee8aa3dc15d0e04d7ff8a7 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Thu, 5 Nov 2020 17:47:21 +0800 Subject: [PATCH] TestReader.infer_img to Global.infer_img --- configs/det/det_db_icdar15_reader.yml | 1 - configs/det/det_east_icdar15_reader.yml | 1 - configs/det/det_mv3_db.yml | 1 + configs/det/det_mv3_db_v1.1.yml | 1 + configs/det/det_mv3_east.yml | 1 + configs/det/det_r18_vd_db_v1.1.yml | 1 + configs/det/det_r50_vd_db.yml | 1 + configs/det/det_r50_vd_east.yml | 1 + configs/det/det_r50_vd_sast_icdar15.yml | 1 + configs/det/det_r50_vd_sast_totaltext.yml | 1 + configs/det/det_sast_icdar15_reader.yml | 1 - configs/det/det_sast_totaltext_reader.yml | 1 - doc/doc_ch/detection.md | 10 +++++----- doc/doc_en/detection_en.md | 8 ++++---- doc/doc_en/recognition_en.md | 4 ++-- tools/infer_det.py | 14 ++++++++++---- tools/program.py | 5 ++++- 17 files changed, 33 insertions(+), 20 deletions(-) diff --git a/configs/det/det_db_icdar15_reader.yml b/configs/det/det_db_icdar15_reader.yml index 6258a304..6c683361 100755 --- a/configs/det/det_db_icdar15_reader.yml +++ b/configs/det/det_db_icdar15_reader.yml @@ -15,7 +15,6 @@ EvalReader: TestReader: reader_function: ppocr.data.det.dataset_traversal,EvalTestReader process_function: ppocr.data.det.db_process,DBProcessTest - infer_img: img_set_dir: ./train_data/icdar2015/text_localization/ label_file_path: ./train_data/icdar2015/text_localization/test_icdar2015_label.txt do_eval: True diff --git a/configs/det/det_east_icdar15_reader.yml b/configs/det/det_east_icdar15_reader.yml index 060ed4dd..f2df30ca 100755 --- a/configs/det/det_east_icdar15_reader.yml +++ b/configs/det/det_east_icdar15_reader.yml @@ -17,7 +17,6 @@ EvalReader: TestReader: reader_function: ppocr.data.det.dataset_traversal,EvalTestReader process_function: ppocr.data.det.east_process,EASTProcessTest - infer_img: img_set_dir: ./train_data/icdar2015/text_localization/ label_file_path: ./train_data/icdar2015/text_localization/test_icdar2015_label.txt do_eval: True diff --git a/configs/det/det_mv3_db.yml b/configs/det/det_mv3_db.yml index 91a8e86f..24443a8f 100755 --- a/configs/det/det_mv3_db.yml +++ b/configs/det/det_mv3_db.yml @@ -16,6 +16,7 @@ Global: checkpoints: save_res_path: ./output/det_db/predicts_db.txt save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_mv3_db_v1.1.yml b/configs/det/det_mv3_db_v1.1.yml index afc11aa0..3cd7e34e 100755 --- a/configs/det/det_mv3_db_v1.1.yml +++ b/configs/det/det_mv3_db_v1.1.yml @@ -16,6 +16,7 @@ Global: checkpoints: save_res_path: ./output/det_db/predicts_db.txt save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_mv3_east.yml b/configs/det/det_mv3_east.yml index 67b82fff..14f453c7 100755 --- a/configs/det/det_mv3_east.yml +++ b/configs/det/det_mv3_east.yml @@ -15,6 +15,7 @@ Global: checkpoints: save_res_path: ./output/det_east/predicts_east.txt save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_r18_vd_db_v1.1.yml b/configs/det/det_r18_vd_db_v1.1.yml index f7cfe57f..c850599b 100755 --- a/configs/det/det_r18_vd_db_v1.1.yml +++ b/configs/det/det_r18_vd_db_v1.1.yml @@ -15,6 +15,7 @@ Global: save_res_path: ./output/det_r18_vd_db/predicts_db.txt checkpoints: save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_r50_vd_db.yml b/configs/det/det_r50_vd_db.yml index 9a3b77e7..726ecd8e 100755 --- a/configs/det/det_r50_vd_db.yml +++ b/configs/det/det_r50_vd_db.yml @@ -15,6 +15,7 @@ Global: save_res_path: ./output/det_db/predicts_db.txt checkpoints: save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_r50_vd_east.yml b/configs/det/det_r50_vd_east.yml index 8d868199..2fb8e5cf 100755 --- a/configs/det/det_r50_vd_east.yml +++ b/configs/det/det_r50_vd_east.yml @@ -15,6 +15,7 @@ Global: save_res_path: ./output/det_east/predicts_east.txt checkpoints: save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_r50_vd_sast_icdar15.yml b/configs/det/det_r50_vd_sast_icdar15.yml index f1ecd61d..02593293 100644 --- a/configs/det/det_r50_vd_sast_icdar15.yml +++ b/configs/det/det_r50_vd_sast_icdar15.yml @@ -15,6 +15,7 @@ Global: save_res_path: ./output/det_sast/predicts_sast.txt checkpoints: save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_r50_vd_sast_totaltext.yml b/configs/det/det_r50_vd_sast_totaltext.yml index ec42ce6d..96522852 100644 --- a/configs/det/det_r50_vd_sast_totaltext.yml +++ b/configs/det/det_r50_vd_sast_totaltext.yml @@ -15,6 +15,7 @@ Global: save_res_path: ./output/det_sast/predicts_sast.txt checkpoints: save_inference_dir: + infer_img: Architecture: function: ppocr.modeling.architectures.det_model,DetModel diff --git a/configs/det/det_sast_icdar15_reader.yml b/configs/det/det_sast_icdar15_reader.yml index ee45a85d..db5c6ac6 100644 --- a/configs/det/det_sast_icdar15_reader.yml +++ b/configs/det/det_sast_icdar15_reader.yml @@ -20,5 +20,4 @@ EvalReader: TestReader: reader_function: ppocr.data.det.dataset_traversal,EvalTestReader process_function: ppocr.data.det.sast_process,SASTProcessTest - infer_img: ./train_data/icdar2015/text_localization/ch4_test_images/img_11.jpg max_side_len: 1536 diff --git a/configs/det/det_sast_totaltext_reader.yml b/configs/det/det_sast_totaltext_reader.yml index 92503d9f..d303d176 100644 --- a/configs/det/det_sast_totaltext_reader.yml +++ b/configs/det/det_sast_totaltext_reader.yml @@ -20,5 +20,4 @@ EvalReader: TestReader: reader_function: ppocr.data.det.dataset_traversal,EvalTestReader process_function: ppocr.data.det.sast_process,SASTProcessTest - infer_img: ./train_data/afs/total_text/Images/Test/img623.jpg max_side_len: 768 diff --git a/doc/doc_ch/detection.md b/doc/doc_ch/detection.md index 3945b7f0..5796114d 100644 --- a/doc/doc_ch/detection.md +++ b/doc/doc_ch/detection.md @@ -17,7 +17,7 @@ wget -P ./train_data/ https://paddleocr.bj.bcebos.com/dataset/test_icdar2015_la PaddleOCR 也提供了数据格式转换脚本,可以将官网 label 转换支持的数据格式。 数据转换工具在 `train_data/gen_label.py`, 这里以训练集为例: ``` -# 将官网下载的标签文件转换为 train_icdar2015_label.txt +# 将官网下载的标签文件转换为 train_icdar2015_label.txt python gen_label.py --mode="det" --root_path="icdar_c4_train_imgs/" \ --input_path="ch4_training_localization_transcription_gt" \ --output_label="train_icdar2015_label.txt" @@ -74,7 +74,7 @@ tar -xf ./pretrain_models/MobileNetV3_large_x0_5_pretrained.tar ./pretrain_model ```shell # 训练 mv3_db 模型,并将训练日志保存为 tain_det.log -python3 tools/train.py -c configs/det/det_mv3_db_v1.1.yml \ +python3 tools/train.py -c configs/det/det_mv3_db_v1.1.yml \ -o Global.pretrain_weights=./pretrain_models/MobileNetV3_large_x0_5_pretrained/ \ 2>&1 | tee train_det.log ``` @@ -119,16 +119,16 @@ python3 tools/eval.py -c configs/det/det_mv3_db_v1.1.yml -o Global.checkpoints= 测试单张图像的检测效果 ```shell -python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o TestReader.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" +python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o Global.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" ``` 测试DB模型时,调整后处理阈值, ```shell -python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o TestReader.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" PostProcess.box_thresh=0.6 PostProcess.unclip_ratio=1.5 +python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o Global.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" PostProcess.box_thresh=0.6 PostProcess.unclip_ratio=1.5 ``` 测试文件夹下所有图像的检测效果 ```shell -python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o TestReader.infer_img="./doc/imgs_en/" Global.checkpoints="./output/det_db/best_accuracy" +python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o Global.infer_img="./doc/imgs_en/" Global.checkpoints="./output/det_db/best_accuracy" ``` diff --git a/doc/doc_en/detection_en.md b/doc/doc_en/detection_en.md index 96928364..2d9983be 100644 --- a/doc/doc_en/detection_en.md +++ b/doc/doc_en/detection_en.md @@ -27,7 +27,7 @@ The provided annotation file format is as follow, seperated by "\t": " Image file name Image annotation information encoded by json.dumps" ch4_test_images/img_61.jpg [{"transcription": "MASA", "points": [[310, 104], [416, 141], [418, 216], [312, 179]]}, {...}] ``` -The image annotation after **json.dumps()** encoding is a list containing multiple dictionaries. +The image annotation after **json.dumps()** encoding is a list containing multiple dictionaries. The `points` in the dictionary represent the coordinates (x, y) of the four points of the text box, arranged clockwise from the point at the upper left corner. @@ -110,16 +110,16 @@ python3 tools/eval.py -c configs/det/det_mv3_db_v1.1.yml -o Global.checkpoints= Test the detection result on a single image: ```shell -python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o TestReader.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" +python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o Global.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" ``` When testing the DB model, adjust the post-processing threshold: ```shell -python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o TestReader.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" PostProcess.box_thresh=0.6 PostProcess.unclip_ratio=1.5 +python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o Global.infer_img="./doc/imgs_en/img_10.jpg" Global.checkpoints="./output/det_db/best_accuracy" PostProcess.box_thresh=0.6 PostProcess.unclip_ratio=1.5 ``` Test the detection result on all images in the folder: ```shell -python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o TestReader.infer_img="./doc/imgs_en/" Global.checkpoints="./output/det_db/best_accuracy" +python3 tools/infer_det.py -c configs/det/det_mv3_db_v1.1.yml -o Global.infer_img="./doc/imgs_en/" Global.checkpoints="./output/det_db/best_accuracy" ``` diff --git a/doc/doc_en/recognition_en.md b/doc/doc_en/recognition_en.md index 41b00c52..1f1195c2 100644 --- a/doc/doc_en/recognition_en.md +++ b/doc/doc_en/recognition_en.md @@ -294,7 +294,7 @@ The default prediction picture is stored in `infer_img`, and the weight is speci ``` # Predict English results -python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v1.1/rec_chinese_lite_train_v1.1.yml -o Global.checkpoints={path/to/weights}/best_accuracy TestReader.infer_img=doc/imgs_words/en/word_1.jpg +python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v1.1/rec_chinese_lite_train_v1.1.yml -o Global.checkpoints={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.jpg ``` Input image: @@ -313,7 +313,7 @@ The configuration file used for prediction must be consistent with the training. ``` # Predict Chinese results -python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v1.1/rec_chinese_lite_train_v1.1.yml -o Global.checkpoints={path/to/weights}/best_accuracy TestReader.infer_img=doc/imgs_words/ch/word_1.jpg +python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v1.1/rec_chinese_lite_train_v1.1.yml -o Global.checkpoints={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/ch/word_1.jpg ``` Input image: diff --git a/tools/infer_det.py b/tools/infer_det.py index 1e7fdcc4..4ac441a4 100755 --- a/tools/infer_det.py +++ b/tools/infer_det.py @@ -104,8 +104,8 @@ def main(): save_res_path = config['Global']['save_res_path'] if not os.path.exists(os.path.dirname(save_res_path)): os.makedirs(os.path.dirname(save_res_path)) - with open(save_res_path, "wb") as fout: + with open(save_res_path, "wb") as fout: test_reader = reader_main(config=config, mode='test') tackling_num = 0 for data in test_reader(): @@ -135,9 +135,15 @@ def main(): elif config['Global']['algorithm'] == 'DB': dic = {'maps': outs[0]} elif config['Global']['algorithm'] == 'SAST': - dic = {'f_score': outs[0], 'f_border': outs[1], 'f_tvo': outs[2], 'f_tco': outs[3]} + dic = { + 'f_score': outs[0], + 'f_border': outs[1], + 'f_tvo': outs[2], + 'f_tco': outs[3] + } else: - raise Exception("only support algorithm: ['EAST', 'DB', 'SAST']") + raise Exception( + "only support algorithm: ['EAST', 'DB', 'SAST']") dt_boxes_list = postprocess(dic, ratio_list) for ino in range(img_num): dt_boxes = dt_boxes_list[ino] @@ -151,7 +157,7 @@ def main(): fout.write(otstr.encode()) src_img = cv2.imread(img_name) draw_det_res(dt_boxes, config, src_img, img_name) - + logger.info("success!") diff --git a/tools/program.py b/tools/program.py index beccba55..f1f4b891 100755 --- a/tools/program.py +++ b/tools/program.py @@ -121,7 +121,10 @@ def merge_config(config): global_config.keys(), sub_keys[0]) cur = global_config[sub_keys[0]] for idx, sub_key in enumerate(sub_keys[1:]): - assert (sub_key in cur) + assert ( + sub_key in cur + ), "key {} not in sub_keys: {}, please check your running command.".format( + sub_key, cur) if idx == len(sub_keys) - 2: cur[sub_key] = value else: