topdu commited on
Commit
19c2cbf
·
verified ·
1 Parent(s): 6730f86

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +129 -3
README.md CHANGED
@@ -1,3 +1,129 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MDiff4STR
2
+
3
+ - [MDiff4STR](#mdiff4str)
4
+ - [1. Introduction](#1-introduction)
5
+ - [1.1 Models and Results](#11-models-and-results)
6
+ - [2. Environment](#2-environment)
7
+ - [3. Model Training / Evaluation](#3-model-training--evaluation)
8
+ - [Dataset Preparation](#dataset-preparation)
9
+ - [Training](#training)
10
+ - [Evaluation](#evaluation)
11
+ - [Inference](#inference)
12
+ - [Latency Measurement](#latency-measurement)
13
+ - [Citation](#citation)
14
+
15
+ <a name="1"></a>
16
+
17
+ ## 1. Introduction
18
+
19
+ Paper:
20
+
21
+ > [MDiff4STR: Mask Diffusion Model for Scene Text Recognition](https://arxiv.org/abs/2512.01422)
22
+ > Yongkun Du, Miaomiao Zhao, Songlin Fan, Zhineng Chen\*, Caiyan Jia, Yu-Gang Jiang
23
+
24
+
25
+ <a name="model"></a>
26
+ Mask Diffusion Models (MDMs) have recently emerged as a promising alternative to auto-regressive models (ARMs) for vision-language tasks, owing to their flexible balance of efficiency and accuracy. In this paper, for the first time, we introduce MDMs into the Scene Text Recognition (STR) task. We show that vanilla MDM lags behind ARMs in terms of accuracy, although it improves recognition efficiency. To bridge this gap, we propose MDiff4STR, a Mask Diffusion model enhanced with two key improvement strategies tailored for STR. Specifically, we identify two key challenges in applying MDMs to STR: noising gap between training and inference, and overconfident predictions during inference. Both significantly hinder the performance of MDMs. To mitigate the first issue, we develop six noising strategies that better align training with inference behavior. For the second, we propose a token-replacement noise mechanism that provides a non-mask noise type, encouraging the model to reconsider and revise overly confident but incorrect predictions. We conduct extensive evaluations of MDiff4STR on both standard and challenging STR benchmarks, covering diverse scenarios including irregular, artistic, occluded, and Chinese text, as well as whether the use of pretraining. Across these settings, MDiff4STR consistently outperforms popular STR models, surpassing state-of-the-art ARMs in accuracy, while maintaining fast inference with only three denoising steps.
27
+
28
+ ### 1.1 Models and Results
29
+
30
+ The accuracy (%) and model files of MDiff4STR on the public dataset of scene text recognition are as follows:
31
+
32
+ Download all Configs, Models, and Logs from [HuggingFace Model](https://huggingface.co/topdu/MDiff4STR).
33
+
34
+
35
+ - Test on Common Benchmarks from [PARSeq](https://github.com/baudm/parseq):
36
+
37
+ | Model | Training Data | IC13<br/>857 | SVT | IIIT5k<br/>3000 | IC15<br/>1811 | SVTP | CUTE80 | Avg | Config&Model&Log |
38
+ | :------: | :----------------------------------------------------------: | :----------: | :--: | :-------------: | :-----------: | :--: | :----: | :---: | :-----------------------------------------------------------------------: |
39
+ | MDiff4STR-B | Synthetic datasets (MJ+ST) | 98.1 |95.8 |98.2| 88.1 |91.6 |96.9 |94.81| [HuggingFace Model](https://huggingface.co/topdu/MDiff4STR/tree/main/mdiff4str_base_syn) |
40
+ | MDiff4STR-S | [Union14M-L-Filter](../../../docs/svtrv2.md#dataset-details) | 99.0 |98.3 |98.4 |90.2 |94.9 |97.6 |96.38 | [HuggingFace Model](https://huggingface.co/topdu/MDiff4STR/tree/main/mdiff4str_small) |
41
+ | MDiff4STR-B | [Union14M-L-Filter](../../../docs/svtrv2.md#dataset-details) | 99.2 |98.3 |99.1 |91.6 |97.1 |98.6 |97.30 | [HuggingFace Model](https://huggingface.co/topdu/MDiff4STR/tree/main/mdiff4str_base) |
42
+
43
+ - Test on Union14M-L benchmark from [Union14M](https://github.com/Mountchicken/Union14M/).
44
+
45
+ | Model | Traing Data | Curve | Multi-<br/>Oriented | Artistic | Contextless | Salient | Multi-<br/>word | General | Avg | Config&Model&Log |
46
+ | :------: | :----------------------------------------------------------: | :---: | :-----------------: | :------: | :---------: | :-----: | :-------------: | :-----: | :---: | :---------------------: |
47
+ | MDiff4STR-B | Synthetic datasets (MJ+ST) | 79.8 |30.2 |64.0 |68.2 |80.8 |66.9 |67.4 |65.33| Same as the above table |
48
+ | MDiff4STR-S | [Union14M-L-Filter](../../../docs/svtrv2.md#dataset-details) | 91.8 |94.0 |80.2 |85.1 |87.3 |84.8 |85.9 |87.03 | Same as the above table |
49
+ | MDiff4STR-B | [Union14M-L-Filter](../../../docs/svtrv2.md#dataset-details) | 93.7 |94.4 |82.1 |86.1 |87.7 |88.3 |86.8 |88.44 | Same as the above table |
50
+
51
+
52
+ - Training and test on Chinese dataset, from [Chinese Benckmark](https://github.com/FudanVI/benchmarking-chinese-text-recognition).
53
+
54
+ | Model | Scene | Web | Document | Handwriting | Avg | Config&Model&Log |
55
+ | :------: | :---: | :--: | :------: | :---------: | :---: | :-----------------------------------------------------------------------------------------------------: |
56
+ | MDiff4STR-S | 85.2 | 84.1 | 99.6 | 66.7 | 83.89 | [HuggingFace Model](https://huggingface.co/topdu/MDiff4STR/tree/main/mdiff4str_small_ch) |
57
+ | MDiff4STR-B | 85.7 | 84.7 | 99.6 | 67.0 | 84.25 | [HuggingFace Model](https://huggingface.co/topdu/MDiff4STR/tree/main/mdiff4str_base_ch) |
58
+
59
+ <a name="2"></a>
60
+
61
+ ## 2. Environment
62
+
63
+ - [PyTorch](http://pytorch.org/) version >= 1.13.0
64
+ - Python version >= 3.7
65
+
66
+ ```shell
67
+ git clone -b develop https://github.com/Topdu/OpenOCR.git
68
+ cd OpenOCR
69
+ # Ubuntu 20.04 Cuda 11.8
70
+ conda create -n openocr python==3.8
71
+ conda activate openocr
72
+ conda install pytorch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 pytorch-cuda=11.8 -c pytorch -c nvidia
73
+ pip install -r requirements.txt
74
+ ```
75
+
76
+ <a name="3"></a>
77
+
78
+ ## 3. Model Training / Evaluation
79
+
80
+ ### Dataset Preparation
81
+
82
+ Referring to [Downloading Datasets](../../../docs/svtrv2.md#downloading-datasets)
83
+
84
+ ### Training
85
+
86
+ ```shell
87
+ # First stage
88
+ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --nproc_per_node=4 tools/train_rec.py --c configs/rec/mdiff4str/svtrv2_mdiffdecoder_base.yml
89
+
90
+ # For Multi RTX 4090
91
+ NCCL_P2P_DISABLE=1 CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.launch --master_port=23333 --nproc_per_node=4 tools/train_rec.py --c configs/rec/mdiff4str/svtrv2_mdiffdecoder_base.yml
92
+ # 20epoch runs for about 6 hours
93
+ ```
94
+
95
+ ### Evaluation
96
+
97
+ ```shell
98
+ # Common, Union14M-Benchmark, OST
99
+ python tools/eval_rec_all_en.py --c configs/rec/mdiff4str/svtrv2_mdiffdecoder_base.yml
100
+ ```
101
+
102
+ After a successful run, the results are saved in a csv file in `output_dir` in the config file.
103
+
104
+ ### Inference
105
+
106
+ ```shell
107
+ python tools/infer_rec.py --c configs/rec/mdiff4str/svtrv2_mdiffdecoder_base.yml --o Global.infer_img=/path/img_fold or /path/img_file
108
+ ```
109
+
110
+ ### Latency Measurement
111
+
112
+ Firstly, downloading the IIIT5K images from [Google Drive](https://drive.google.com/drive/folders/1Po1LSBQb87DxGJuAgLNxhsJ-pdXxpIfS?usp=drive_link). Then, running the following command:
113
+
114
+ ```shell
115
+ python tools/infer_rec.py --c configs/rec/mdiff4str/svtrv2_mdiffdecoder_base.yml --o Global.infer_img=../iiit5k_test_image
116
+ ```
117
+
118
+ ## Citation
119
+
120
+ If you find our method useful for your reserach, please cite:
121
+
122
+ ```bibtex
123
+ @inproceedings{Du2025MDiff5STR,
124
+ title={MDiff4STR: Mask Diffusion Model for Scene Text Recognition},
125
+ author={Yongkun Du and Miaomiao Zhao and Songlin Fan and Zhineng Chen and Caiyan Jia and Yu-Gang Jiang},
126
+ booktitle={AAAI Oral},
127
+ year={2025},
128
+ }
129
+ ```