diff --git a/configs/rec/multi_languages/rec_en_lite_train.yml b/configs/rec/multi_languages/rec_en_lite_train.yml index 8b08d9f788415d63028480183a52630bbe245db0..128424b4d3a5631f8237f6cd596c901990ff2277 100644 --- a/configs/rec/multi_languages/rec_en_lite_train.yml +++ b/configs/rec/multi_languages/rec_en_lite_train.yml @@ -16,7 +16,7 @@ Global: loss_type: ctc distort: false use_space_char: false - reader_yml: ./configs/rec/rec_en_reader.yml + reader_yml: ./configs/rec/multi_languages/rec_en_reader.yml pretrain_weights: checkpoints: save_inference_dir: diff --git a/configs/rec/multi_languages/rec_french_lite_train.yml b/configs/rec/multi_languages/rec_french_lite_train.yml index 49d4d3df089a4749674b47f45a97a54abe95ffa2..2cf54c427eb6a7c64f4b54b021c44013a1dc1d6a 100755 --- a/configs/rec/multi_languages/rec_french_lite_train.yml +++ b/configs/rec/multi_languages/rec_french_lite_train.yml @@ -16,7 +16,7 @@ Global: loss_type: ctc distort: true use_space_char: false - reader_yml: ./configs/rec/rec_french_reader.yml + reader_yml: ./configs/rec/multi_languages/rec_french_reader.yml pretrain_weights: checkpoints: save_inference_dir: diff --git a/configs/rec/multi_languages/rec_ger_lite_train.yml b/configs/rec/multi_languages/rec_ger_lite_train.yml index 0ccadd0ad9a91c18b998a07a7c10184893327762..beb1755b105fea9cbade9f35ceac15d380651f37 100755 --- a/configs/rec/multi_languages/rec_ger_lite_train.yml +++ b/configs/rec/multi_languages/rec_ger_lite_train.yml @@ -16,7 +16,7 @@ Global: loss_type: ctc distort: true use_space_char: false - reader_yml: ./configs/rec/rec_ger_reader.yml + reader_yml: ./configs/rec/multi_languages/rec_ger_reader.yml pretrain_weights: checkpoints: save_inference_dir: diff --git a/configs/rec/multi_languages/rec_japan_lite_train.yml b/configs/rec/multi_languages/rec_japan_lite_train.yml index 2d3b388a5c9389fc27e23a5a295f9c4c70405a36..fbbab33eadd2901d9eac93f49e737e92d9441270 100755 --- a/configs/rec/multi_languages/rec_japan_lite_train.yml +++ b/configs/rec/multi_languages/rec_japan_lite_train.yml @@ -16,7 +16,7 @@ Global: loss_type: ctc distort: true use_space_char: false - reader_yml: ./configs/rec/rec_japan_reader.yml + reader_yml: ./configs/rec/multi_languages/rec_japan_reader.yml pretrain_weights: checkpoints: save_inference_dir: diff --git a/configs/rec/multi_languages/rec_korean_lite_train.yml b/configs/rec/multi_languages/rec_korean_lite_train.yml index ad55d821c63b987150a140a5924407a259d48c66..29cc08aaefb017c690551e030a57e85ebb21e2dd 100755 --- a/configs/rec/multi_languages/rec_korean_lite_train.yml +++ b/configs/rec/multi_languages/rec_korean_lite_train.yml @@ -16,7 +16,7 @@ Global: loss_type: ctc distort: true use_space_char: false - reader_yml: ./configs/rec/rec_korean_reader.yml + reader_yml: ./configs/rec/multi_languages/rec_korean_reader.yml pretrain_weights: checkpoints: save_inference_dir: diff --git a/doc/doc_ch/inference.md b/doc/doc_ch/inference.md index 431cdb5a4a9f24cf5862c159d51be2a07e9d4047..709a07515c316cdfd60b74f0b090d4baeeb290a7 100644 --- a/doc/doc_ch/inference.md +++ b/doc/doc_ch/inference.md @@ -24,6 +24,7 @@ inference 模型(`fluid.io.save_inference_model`保存的模型) - [2. 基于CTC损失的识别模型推理](#基于CTC损失的识别模型推理) - [3. 基于Attention损失的识别模型推理](#基于Attention损失的识别模型推理) - [4. 自定义文本识别字典的推理](#自定义文本识别字典的推理) + - [5. 多语言模型的推理](#多语言模型的推理) - [四、方向分类模型推理](#方向识别模型推理) - [1. 方向分类模型推理](#方向分类模型推理) @@ -305,6 +306,22 @@ dict_character = list(self.character_str) python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./your inference model" --rec_image_shape="3, 32, 100" --rec_char_type="en" --rec_char_dict_path="your text dict path" ``` + +### 5. 多语言模型的推理 +如果您需要预测的是其他语言模型,在使用inference模型预测时,需要通过`--rec_char_dict_path`指定使用的字典路径, 同时为了得到正确的可视化结果, +需要通过 `--vis_font_path` 指定可视化的字体路径,`doc/` 路径下有默认提供的小语种字体,例如韩文识别: + +``` +python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/korean/1.jpg" --rec_model_dir="./your inference model" --rec_char_type="korean" --rec_char_dict_path="ppocr/utils/korean_dict.txt" --vis_font_path="doc/korean.ttf" +``` +![](../imgs_words/korean/1.jpg) + +执行命令后,上图的预测结果为: +``` text +2020-09-19 16:15:05,076-INFO: index: [205 206 38 39] +2020-09-19 16:15:05,077-INFO: word : 바탕으로 +2020-09-19 16:15:05,077-INFO: score: 0.9171358942985535 +``` ## 四、方向分类模型推理 diff --git a/doc/doc_ch/models_list.md b/doc/doc_ch/models_list.md index 497140592ea4f4cbfe2000146b6903844f3f9872..a6d47f4fdf17ad6b954a107c46a57f55983147f9 100644 --- a/doc/doc_ch/models_list.md +++ b/doc/doc_ch/models_list.md @@ -49,10 +49,11 @@ PaddleOCR提供的可下载模型包括`预测模型`、`训练模型`、`预训 #### 3. 多语言识别模型(更多语言持续更新中...) |模型名称|模型简介|预测模型大小|下载地址| |-|-|-|-| -|-|法文识别|-|[预测模型]() / [训练模型]()| -|-|德文识别|-|[预测模型]() / [训练模型]()| -|-|韩文识别|-|[预测模型]() / [训练模型]()| -|-|日文识别|-|[预测模型]() / [训练模型]()| +| french_ppocr_mobile_v1.1_rec |法文识别|2.1M|[预测模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/fr/french_ppocr_mobile_v1.1_rec_infer.tar) / [训练模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/fr/french_ppocr_mobile_v1.1_rec_train.tar)| +| german_ppocr_mobile_v1.1_rec |德文识别|2.1M|[预测模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/ge/german_ppocr_mobile_v1.1_rec_infer.tar) / [训练模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/ge/german_ppocr_mobile_v1.1_rec_train.tar)| +| korean_ppocr_mobile_v1.1_rec |韩文识别|3.4M|[预测模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/kr/korean_ppocr_mobile_v1.1_rec_infer.tar) / [训练模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/kr/korean_ppocr_mobile_v1.1_rec_train.tar)| +| japan_ppocr_mobile_v1.1_rec |日文识别|3.7M|[预测模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/jp/japan_ppocr_mobile_v1.1_rec_infer.tar) / [训练模型](https://paddleocr.bj.bcebos.com/20-09-22/mobile/jp/japan_ppocr_mobile_v1.1_rec_train.tar)| + ### 三、文本方向分类模型 diff --git a/doc/doc_ch/recognition.md b/doc/doc_ch/recognition.md index 7f49882d049c9cb3694c1f1048d258db0d14fe6c..c8955f7fe1c7022cf68155be330fad307c68fe43 100644 --- a/doc/doc_ch/recognition.md +++ b/doc/doc_ch/recognition.md @@ -208,7 +208,19 @@ Optimizer: ``` **注意,预测/评估时的配置文件请务必与训练一致。** +- 小语种 +PaddleOCR也提供了多语言的, `configs/rec/multi_languages` 路径下的提供了多语言的配置文件,目前PaddleOCR支持的多语言算法有: + +| 配置文件 | 算法名称 | backbone | trans | seq | pred | language | +| :--------: | :-------: | :-------: | :-------: | :-----: | :-----: | :-----: | +| rec_en_lite_train.yml | CRNN | Mobilenet_v3 small 0.5 | None | BiLSTM | ctc | 英语 | +| rec_french_lite_train.yml | CRNN | Mobilenet_v3 small 0.5 | None | BiLSTM | ctc | 法语 | +| rec_ger_lite_train.yml | CRNN | Mobilenet_v3 small 0.5 | None | BiLSTM | ctc | 德语 | +| rec_japan_lite_train.yml | CRNN | Mobilenet_v3 small 0.5 | None | BiLSTM | ctc | 日语 | +| rec_korean_lite_train.yml | CRNN | Mobilenet_v3 small 0.5 | None | BiLSTM | ctc | 韩语 | + +多语言模型训练方式与中文模型一致,训练数据集均为100w的合成数据,少量的字体和测试数据可以在[百度网盘]()上下载。 ### 评估 diff --git a/doc/french.ttf b/doc/french.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ab68fb197d4479b3b6dec6e85bd5cbaf433a87c5 Binary files /dev/null and b/doc/french.ttf differ diff --git a/doc/german.ttf b/doc/german.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ab68fb197d4479b3b6dec6e85bd5cbaf433a87c5 Binary files /dev/null and b/doc/german.ttf differ diff --git a/doc/imgs_words/french/1.jpg b/doc/imgs_words/french/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..077ca28e70b74ed07fa637011c80219aecc448d5 Binary files /dev/null and b/doc/imgs_words/french/1.jpg differ diff --git a/doc/imgs_words/french/2.jpg b/doc/imgs_words/french/2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..38a73caa621710a7eb7378603e0152ba9c14dd41 Binary files /dev/null and b/doc/imgs_words/french/2.jpg differ diff --git a/doc/imgs_words/german/1.jpg b/doc/imgs_words/german/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d26ec9ed14de65c2d27e37693ff0da133e774b94 Binary files /dev/null and b/doc/imgs_words/german/1.jpg differ diff --git a/doc/imgs_words/japan/1.jpg b/doc/imgs_words/japan/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..684879749764a1b6063da32d7910bff911e855f4 Binary files /dev/null and b/doc/imgs_words/japan/1.jpg differ diff --git a/doc/imgs_words/korean/1.jpg b/doc/imgs_words/korean/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..48a89389ae880783a39a13e9b06a861b88948fba Binary files /dev/null and b/doc/imgs_words/korean/1.jpg differ diff --git a/doc/imgs_words/korean/2.jpg b/doc/imgs_words/korean/2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b24f28914d574be44e147943d906f8634f149ed5 Binary files /dev/null and b/doc/imgs_words/korean/2.jpg differ diff --git a/doc/japan.ttc b/doc/japan.ttc new file mode 100644 index 0000000000000000000000000000000000000000..ad68243b968fc87b207928594c585039859b75a9 Binary files /dev/null and b/doc/japan.ttc differ diff --git a/doc/korean.ttf b/doc/korean.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e638ce37f67ff1cd9babf73387786eaeb5c52968 Binary files /dev/null and b/doc/korean.ttf differ diff --git a/tools/infer/predict_system.py b/tools/infer/predict_system.py index 3e6be234c68dcd82f0f9e844f3ad2859000cec88..29c4d7e8e35ceda3966dfcadcca5f0ae985d1bb1 100755 --- a/tools/infer/predict_system.py +++ b/tools/infer/predict_system.py @@ -133,6 +133,7 @@ def main(args): image_file_list = get_image_file_list(args.image_dir) text_sys = TextSystem(args) is_visualize = True + font_path = args.vis_font_path for image_file in image_file_list: img, flag = check_and_read_gif(image_file) if not flag: @@ -160,7 +161,7 @@ def main(args): scores = [rec_res[i][1] for i in range(len(rec_res))] draw_img = draw_ocr( - image, boxes, txts, scores, drop_score=drop_score) + image, boxes, txts, scores, drop_score=drop_score, font_path=font_path) draw_img_save = "./inference_results/" if not os.path.exists(draw_img_save): os.makedirs(draw_img_save) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 18acef224da2564d2ca4a66777de01873d5edb49..98eaee2d2ff6dcfcc2c90af24bdbfadd274f7793 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -71,6 +71,10 @@ def parse_args(): type=str, default="./ppocr/utils/ppocr_keys_v1.txt") parser.add_argument("--use_space_char", type=str2bool, default=True) + parser.add_argument( + "--vis_font_path", + type=str, + default="./doc/simfang.ttf") # params for text classifier parser.add_argument("--use_angle_cls", type=str2bool, default=False) @@ -199,7 +203,7 @@ def draw_ocr(image, return image -def draw_ocr_box_txt(image, boxes, txts): +def draw_ocr_box_txt(image, boxes, txts, font_path="./doc/simfang.ttf"): h, w = image.height, image.width img_left = image.copy() img_right = Image.new('RGB', (w, h), (255, 255, 255)) @@ -226,7 +230,7 @@ def draw_ocr_box_txt(image, boxes, txts): if box_height > 2 * box_width: font_size = max(int(box_width * 0.9), 10) font = ImageFont.truetype( - "./doc/simfang.ttf", font_size, encoding="utf-8") + font_path, font_size, encoding="utf-8") cur_y = box[0][1] for c in txt: char_size = font.getsize(c) @@ -236,7 +240,7 @@ def draw_ocr_box_txt(image, boxes, txts): else: font_size = max(int(box_height * 0.8), 10) font = ImageFont.truetype( - "./doc/simfang.ttf", font_size, encoding="utf-8") + font_path, font_size, encoding="utf-8") draw_right.text( [box[0][0], box[0][1]], txt, fill=(0, 0, 0), font=font) img_left = Image.blend(image, img_left, 0.5)