open-mmlab / mmocr

OpenMMLab Text Detection, Recognition and Understanding Toolbox
https://mmocr.readthedocs.io/en/dev-1.x/
Apache License 2.0
4.28k stars 743 forks source link

搜了一圈发现不支持中文的检测和识别 #992

Closed tangjinou closed 2 years ago

tangjinou commented 2 years ago

如题

英文的检测和识别运行得较好,但中文的检测和识别没有发现任何文档或pretrain的模型

mm-assistant[bot] commented 2 years ago

Please use English or English & Chinese for issues so that we could have broader discussion.

xinke-wang commented 2 years ago

Hi, MMOCR currently provides a pre-trained SAR model for Chinese recognition. More pre-trained models for Chinese and multi-lingual detection & recognition are on the way; please stay tuned.

tangjinou commented 2 years ago

Hi, MMOCR currently provides a pre-trained SAR model for Chinese recognition. More pre-trained models for Chinese and multi-lingual detection & recognition are on the way; please stay tuned.

OK, when I use SAR_CN, like this "python mmocr/utils/ocr.py demo/word_1.jpg --recog SAR_CN --output demo/"

something error happened like this

"FileNotFoundError: SARNet: AttnConvertor: [Errno 2] No such file or directory: 'data/chineseocr/labels/dict_printed_chinese_english_digits.txt'"

here is detail:

root@3b5cb35cb3b4:/mmocr# python mmocr/utils/ocr.py demo/word_1.jpg --recog SAR_CN --output demo/ load checkpoint from http path: https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.pth Traceback (most recent call last): File "/opt/conda/lib/python3.8/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(**args) File "/mmocr/mmocr/models/textrecog/convertors/attn.py", line 36, in init super().init(dict_type, dict_file, dict_list) File "/mmocr/mmocr/models/textrecog/convertors/base.py", line 38, in init for line_num, line in enumerate(list_from_file(dict_file)): File "/mmocr/mmocr/utils/fileio.py", line 35, in list_from_file with open(filename, 'r', encoding=encoding) as f: FileNotFoundError: [Errno 2] No such file or directory: 'data/chineseocr/labels/dict_printed_chinese_english_digits.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/conda/lib/python3.8/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(**args) File "/mmocr/mmocr/models/textrecog/recognizer/encode_decode_recognizer.py", line 34, in init self.label_convertor = build_convertor(label_convertor) File "/mmocr/mmocr/models/builder.py", line 37, in build_convertor return build_from_cfg(cfg, CONVERTORS) File "/opt/conda/lib/python3.8/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') FileNotFoundError: AttnConvertor: [Errno 2] No such file or directory: 'data/chineseocr/labels/dict_printed_chinese_english_digits.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "mmocr/utils/ocr.py", line 861, in main() File "mmocr/utils/ocr.py", line 856, in main ocr = MMOCR(*vars(args)) File "mmocr/utils/ocr.py", line 398, in init self.recog_model = init_detector( File "/mmocr/mmocr/apis/inference.py", line 43, in init_detector model = build_detector(config.model, test_cfg=config.get('test_cfg')) File "/mmocr/mmocr/models/builder.py", line 151, in build_detector return DETECTORS.build( File "/opt/conda/lib/python3.8/site-packages/mmcv/utils/registry.py", line 215, in build return self.build_func(args, **kwargs, registry=self) File "/opt/conda/lib/python3.8/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/opt/conda/lib/python3.8/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') FileNotFoundError: SARNet: AttnConvertor: [Errno 2] No such file or directory: 'data/chineseocr/labels/dict_printed_chinese_english_digits.txt'

tangjinou commented 2 years ago

@gaotongxiao

xinke-wang commented 2 years ago

You have to first download the Chinese dict and put it to the correct path.

tangjinou commented 2 years ago

You have to first download the Chinese dict and put it to the correct path.

why I use other reg models like sar and crnn etc , the model will be downloaded ? It seems only sar_cn have this problem?

tangjinou commented 2 years ago

You have to first download the Chinese dict and put it to the correct path.

when I use wget "https://download.openmmlab.com/mmocr/textrecog/sar/dict_printed_chinese_english_digits.txt" to /data/chineseocr/labels/ , It seems ok;

But the result is not OK, image

xinke-wang commented 2 years ago

Hi, I ran the following command on the provided image and the result looks fine.

python mmocr/utils/ocr.py demo.png --det None --recog SAR_CN --output out.png

image

tangjinou commented 2 years ago
```shell
python mmocr/utils/ocr.py demo.png --det None --recog SAR_CN --output out.png

OK,  
it seems  "python mmocr/utils/ocr.py demo/word_1.jpg --recog SAR_CN --output demo/out.png" is not ok

but "python mmocr/utils/ocr.py demo/word_1.jpg --det None --recog SAR_CN --output demo/out.png" is ok

the difference is only if use "--det None"

BTW, Is any det model with chinese?

xinke-wang commented 2 years ago
  1. Yes, since your input is a cropped image, it is unnecessary to use a detection model; if the det model is not specified to None here, it will use PANet_IC15 as the detector by default.
  2. MMOCR currently does not provide a Chinese-specific pre-trained model for the detector, however, you may try the model pre-trained on ICDAR2017 (such as MaskRCNN_IC17), since this is a multilingual dataset containing Chinese training samples.
tangjinou commented 2 years ago
  1. Yes, since your input is a cropped image, it is unnecessary to use a detection model; if the det model is not specified to None here, it will use PANet_IC15 as the detector by default.
  2. MMOCR currently does not provide a Chinese-specific pre-trained model for the detector, however, you may try the model pre-trained on ICDAR2017 (such as MaskRCNN_IC17), since this is a multilingual dataset containing Chinese training samples.

1 It's OK . May be some tips without reading code or Answering question will be fine. 3ks. 2 MaskRCNN is old and slow, any other models will be given?

xinke-wang commented 2 years ago

Currently, released detection models are primarily trained on English data. However, they can be used for Chinese detection as well, please have a try. If you have your own Chinese data, it might be better to train your own model for the best performance. In addition, we are going to release more Chinese models soon, please stay tuned.

Please also refer to issues #243 and #712.

tangjinou commented 2 years ago

Currently, released detection models are primarily trained on English data. However, they can be used for Chinese detection as well, please have a try. If you have your own Chinese data, it might be better to train your own model for the best performance. In addition, we are going to release more Chinese models soon, please stay tuned.

Please also refer to issues #243 and #712.

OK 3KS