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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MonkeyOCRv2 Detection
|
| 2 |
+
|
| 3 |
+
MonkeyOCRv2 Detection integrates the visual encoder from
|
| 4 |
+
[MonkeyOCRv2-AS](https://huggingface.co/zenosai/MonkeyOCRv2-AS) (ViTAEv2-S,
|
| 5 |
+
21M parameters) into **DBNet** and **PSENet** scene text detectors via
|
| 6 |
+
[MMOCR](https://github.com/open-mmlab/mmocr). The four-stage ViTAEv2 features
|
| 7 |
+
(strides 4/8/16/32) are exposed as `res2`–`res5` and fed to the standard FPNC /
|
| 8 |
+
FPNF necks, so no change to the detection heads is required.
|
| 9 |
+
|
| 10 |
+
Training and evaluation follow the official MMOCR protocols on Total-Text,
|
| 11 |
+
CTW1500, and ICDAR2015.
|
| 12 |
+
|
| 13 |
+
## Models and Results
|
| 14 |
+
|
| 15 |
+
Replacing the ImageNet-pretrained ResNet-50 with the MonkeyOCRv2-AS encoder
|
| 16 |
+
consistently improves F-score over both the baseline and the
|
| 17 |
+
[oCLIP](https://github.com/alkan25/oclip)-pretrained backbone. `*` marks
|
| 18 |
+
results reproduced by us with MMOCR.
|
| 19 |
+
|
| 20 |
+
### Total-Text
|
| 21 |
+
|
| 22 |
+
| Method | P | R | F |
|
| 23 |
+
| --- | ---: | ---: | ---: |
|
| 24 |
+
| DBNet* (ResNet-50) | 82.6 | 78.4 | 80.4 |
|
| 25 |
+
| DBNet + oCLIP | 85.1 | 81.7 | 83.4 |
|
| 26 |
+
| **DBNet + MonkeyOCRv2** | **87.7** | 80.1 | **83.7** |
|
| 27 |
+
|
| 28 |
+
### CTW1500
|
| 29 |
+
|
| 30 |
+
| Method | P | R | F |
|
| 31 |
+
| --- | ---: | ---: | ---: |
|
| 32 |
+
| PSENet* (ResNet-50) | 80.1 | 82.7 | 81.4 |
|
| 33 |
+
| PSENet + oCLIP | 82.1 | 85.5 | 83.8 |
|
| 34 |
+
| **PSENet + MonkeyOCRv2** | **88.3** | 82.0 | **85.1** |
|
| 35 |
+
|
| 36 |
+
### ICDAR2015
|
| 37 |
+
|
| 38 |
+
| Method | P | R | F |
|
| 39 |
+
| --- | ---: | ---: | ---: |
|
| 40 |
+
| PSENet* (ResNet-50) | 84.0 | 76.2 | 79.9 |
|
| 41 |
+
| PSENet + oCLIP | 87.3 | 82.6 | 84.9 |
|
| 42 |
+
| **PSENet + MonkeyOCRv2** | **90.4** | 80.3 | **85.0** |
|
| 43 |
+
| DBNet* (ResNet-50) | 88.8 | 81.5 | 85.0 |
|
| 44 |
+
| DBNet + oCLIP | 90.9 | 84.1 | 87.4 |
|
| 45 |
+
| **DBNet + MonkeyOCRv2** | **91.2** | **86.0** | **88.5** |
|
| 46 |
+
|
| 47 |
+
### Checkpoints
|
| 48 |
+
|
| 49 |
+
Download the checkpoints from
|
| 50 |
+
[HB16888/MonkeyOCRv2_det](https://huggingface.co/HB16888/MonkeyOCRv2_det)
|
| 51 |
+
(HuggingFace) or
|
| 52 |
+
[WangXinhan/MonkeyOCRv2_det](https://modelscope.cn/models/WangXinhan/MonkeyOCRv2_det)
|
| 53 |
+
(ModelScope):
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
# HuggingFace
|
| 57 |
+
hf download HB16888/MonkeyOCRv2_det --include "*.pth" --local-dir ./model_weight
|
| 58 |
+
# ModelScope
|
| 59 |
+
modelscope download --model WangXinhan/MonkeyOCRv2_det --local_dir ./model_weight
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
Each checkpoint is the best epoch on the test set, i.e. exactly the row
|
| 63 |
+
reported in the tables above.
|
| 64 |
+
|
| 65 |
+
| Checkpoint | Method | Dataset | Epoch | Config |
|
| 66 |
+
| --- | --- | --- | ---: | --- |
|
| 67 |
+
| dbnet_r50_totaltext.pth | DBNet baseline | Total-Text | 580 | configs/textdet/dbnet/dbnet_resnet50_1200e_totaltext_2gpu.py |
|
| 68 |
+
| dbnet_r50-oclip_totaltext.pth | DBNet + oCLIP | Total-Text | 740 | configs/textdet/dbnet/dbnet_resnet50-oclip_1200e_totaltext_2gpu.py |
|
| 69 |
+
| dbnet_mkv2vitae_totaltext.pth | DBNet + MonkeyOCRv2 | Total-Text | 1000 | configs/textdet/dbnet/dbnet_mkv2vitae_1200e_totaltext_2gpu_adamw.py |
|
| 70 |
+
| psenet_r50_ctw1500.pth | PSENet baseline | CTW1500 | 280 | configs/textdet/psenet/psenet_resnet50_fpnf_600e_ctw1500_2gpu.py |
|
| 71 |
+
| psenet_r50-oclip_ctw1500.pth | PSENet + oCLIP | CTW1500 | 280 | configs/textdet/psenet/psenet_resnet50-oclip_fpnf_600e_ctw1500_2gpu.py |
|
| 72 |
+
| psenet_mkv2vitae_ctw1500.pth | PSENet + MonkeyOCRv2 | CTW1500 | 120 | configs/textdet/psenet/psenet_mkv2vitae_fpnf_600e_ctw1500_4gpu_adamw.py |
|
| 73 |
+
| psenet_r50_icdar2015.pth | PSENet baseline | ICDAR2015 | 400 | configs/textdet/psenet/psenet_resnet50_fpnf_600e_icdar2015_2gpu.py |
|
| 74 |
+
| psenet_r50-oclip_icdar2015.pth | PSENet + oCLIP | ICDAR2015 | 520 | configs/textdet/psenet/psenet_resnet50-oclip_fpnf_600e_icdar2015_2gpu.py |
|
| 75 |
+
| psenet_mkv2vitae_icdar2015.pth | PSENet + MonkeyOCRv2 | ICDAR2015 | 160 | configs/textdet/psenet/psenet_mkv2vitae_fpnf_600e_icdar2015_4gpu_adamw.py |
|
| 76 |
+
| dbnet_r50_icdar2015.pth | DBNet baseline | ICDAR2015 | 980 | configs/textdet/dbnet/dbnet_resnet50_1200e_icdar2015_2gpu.py |
|
| 77 |
+
| dbnet_r50-oclip_icdar2015.pth | DBNet + oCLIP | ICDAR2015 | 1100 | configs/textdet/dbnet/dbnet_resnet50-oclip_1200e_icdar2015_2gpu.py |
|
| 78 |
+
| dbnet_mkv2vitae_icdar2015.pth | DBNet + MonkeyOCRv2 | ICDAR2015 | 420 | configs/textdet/dbnet/dbnet_mkv2vitae_1200e_icdar2015_2gpu_adamw.py |
|
| 79 |
+
|
| 80 |
+
## Environment
|
| 81 |
+
|
| 82 |
+
The reproduced environment uses Python 3.11, PyTorch 2.9.0, CUDA 12.8,
|
| 83 |
+
MMEngine 0.10.7, MMCV 2.0.1, MMOCR 1.0.1, and Transformers 4.57. Baselines
|
| 84 |
+
and oCLIP models were trained on 2 GPUs; the MonkeyOCRv2 PSENet models on 4
|
| 85 |
+
GPUs (NVIDIA GeForce RTX 3090).
|
| 86 |
+
|
| 87 |
+
## Installation
|
| 88 |
+
|
| 89 |
+
This directory is an add-on on top of the official MMOCR v1.0.1. Run:
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
bash install.sh # clones MMOCR v1.0.1 into ./mmocr and patches it
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
The add-on contains:
|
| 96 |
+
|
| 97 |
+
- `mmocr/models/common/backbones/monkeyocr_v2_vitae.py` — MMEngine wrapper
|
| 98 |
+
that loads the HuggingFace MonkeyOCRv2-AS encoder (via `transformers`
|
| 99 |
+
`AutoModel`, `trust_remote_code=True`) and exposes its four stages as
|
| 100 |
+
`res2`–`res5`. Image normalization (ViTAE mean/std) and patch splitting are
|
| 101 |
+
performed inside the backbone; the data preprocessor must use
|
| 102 |
+
`mean=None`, `std=None`, `bgr_to_rgb=True`, `pad_size_divisor=32`.
|
| 103 |
+
- `mmocr/models/textdet/postprocessors/pse_postprocessor.py` — one-line fix
|
| 104 |
+
for the PSE kernel-growing condition (`or` → `and` when filtering by
|
| 105 |
+
`score_threshold`), which improves the PSENet postprocessing quality.
|
| 106 |
+
- `dataset_zoo/ctw1500/textdet.py` — updated MD5 sums and archive layouts
|
| 107 |
+
for the CTW1500 download sources (the official Box/CloudStor archives were
|
| 108 |
+
re-uploaded and no longer match the upstream checksums).
|
| 109 |
+
- `tools/test.py` — accepts `--out` when `test_evaluator` is a plain dict.
|
| 110 |
+
- `tools/dataset_converters/prepare_all_datasets.sh` — prepares ICDAR2015,
|
| 111 |
+
CTW1500, and Total-Text in one go.
|
| 112 |
+
- `configs/textdet/{dbnet,psenet}/` — the 12 training configs listed above.
|
| 113 |
+
|
| 114 |
+
## Pretrained Backbone
|
| 115 |
+
|
| 116 |
+
Download the MonkeyOCRv2-AS visual encoder before training or evaluation:
|
| 117 |
+
|
| 118 |
+
```bash
|
| 119 |
+
hf download zenosai/MonkeyOCRv2-AS --local-dir ./pretrained/monkeyocrv2_as
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
The configs reference `pretrained/monkeyocrv2_as` relative to the MMOCR
|
| 123 |
+
working directory. The weights are identical to the ones used to produce the
|
| 124 |
+
results above (verified by MD5).
|
| 125 |
+
|
| 126 |
+
## Datasets
|
| 127 |
+
|
| 128 |
+
```bash
|
| 129 |
+
cd mmocr
|
| 130 |
+
bash tools/dataset_converters/prepare_all_datasets.sh
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
This prepares `data/icdar2015`, `data/ctw1500`, and `data/totaltext` in the
|
| 134 |
+
MMOCR format. Note that some official CTW1500 download links are currently
|
| 135 |
+
unreliable; we also provide the prepared CTW1500 in MMOCR format at
|
| 136 |
+
[HB16888/CTW1500](https://huggingface.co/datasets/HB16888/CTW1500)
|
| 137 |
+
(HuggingFace) and
|
| 138 |
+
[WangXinhan/CTW1500](https://modelscope.cn/datasets/WangXinhan/CTW1500)
|
| 139 |
+
(ModelScope):
|
| 140 |
+
|
| 141 |
+
```bash
|
| 142 |
+
# HuggingFace
|
| 143 |
+
hf download HB16888/CTW1500 --repo-type dataset --local-dir ./ctw1500_dl
|
| 144 |
+
unzip ctw1500_dl/ctw1500_mmocr.zip -d data/
|
| 145 |
+
# ModelScope
|
| 146 |
+
modelscope download --dataset WangXinhan/CTW1500 --local_dir ./ctw1500_dl
|
| 147 |
+
unzip ctw1500_dl/ctw1500_mmocr.zip -d data/
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
Directory layout:
|
| 151 |
+
|
| 152 |
+
```text
|
| 153 |
+
data/ctw1500/
|
| 154 |
+
├── textdet_imgs/
|
| 155 |
+
│ ├── train/ # 1000 images
|
| 156 |
+
│ └── test/ # 500 images
|
| 157 |
+
├── textdet_train.json
|
| 158 |
+
└── textdet_test.json
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
## Training
|
| 162 |
+
|
| 163 |
+
All commands are run from the MMOCR root directory. Baselines and oCLIP
|
| 164 |
+
models use 2 GPUs (batch size 16 in total); MonkeyOCRv2 PSENet models use 4
|
| 165 |
+
GPUs.
|
| 166 |
+
|
| 167 |
+
```bash
|
| 168 |
+
# ---------- DBNet on Total-Text ----------
|
| 169 |
+
bash tools/dist_train.sh configs/textdet/dbnet/dbnet_resnet50_1200e_totaltext_2gpu.py 2
|
| 170 |
+
bash tools/dist_train.sh configs/textdet/dbnet/dbnet_resnet50-oclip_1200e_totaltext_2gpu.py 2
|
| 171 |
+
bash tools/dist_train.sh configs/textdet/dbnet/dbnet_mkv2vitae_1200e_totaltext_2gpu_adamw.py 2
|
| 172 |
+
|
| 173 |
+
# ---------- PSENet on CTW1500 ----------
|
| 174 |
+
bash tools/dist_train.sh configs/textdet/psenet/psenet_resnet50_fpnf_600e_ctw1500_2gpu.py 2
|
| 175 |
+
bash tools/dist_train.sh configs/textdet/psenet/psenet_resnet50-oclip_fpnf_600e_ctw1500_2gpu.py 2
|
| 176 |
+
bash tools/dist_train.sh configs/textdet/psenet/psenet_mkv2vitae_fpnf_600e_ctw1500_4gpu_adamw.py 4
|
| 177 |
+
|
| 178 |
+
# ---------- PSENet on ICDAR2015 ----------
|
| 179 |
+
bash tools/dist_train.sh configs/textdet/psenet/psenet_resnet50_fpnf_600e_icdar2015_2gpu.py 2
|
| 180 |
+
bash tools/dist_train.sh configs/textdet/psenet/psenet_resnet50-oclip_fpnf_600e_icdar2015_2gpu.py 2
|
| 181 |
+
bash tools/dist_train.sh configs/textdet/psenet/psenet_mkv2vitae_fpnf_600e_icdar2015_4gpu_adamw.py 4
|
| 182 |
+
|
| 183 |
+
# ---------- DBNet on ICDAR2015 ----------
|
| 184 |
+
bash tools/dist_train.sh configs/textdet/dbnet/dbnet_resnet50_1200e_icdar2015_2gpu.py 2
|
| 185 |
+
bash tools/dist_train.sh configs/textdet/dbnet/dbnet_resnet50-oclip_1200e_icdar2015_2gpu.py 2
|
| 186 |
+
bash tools/dist_train.sh configs/textdet/dbnet/dbnet_mkv2vitae_1200e_icdar2015_2gpu_adamw.py 2
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
Notes:
|
| 190 |
+
|
| 191 |
+
- The oCLIP backbone weights (`resnet50-oclip-7ba0c533.pth`) are fetched
|
| 192 |
+
automatically from `download.openmmlab.com` via `init_cfg`.
|
| 193 |
+
- The MonkeyOCRv2 configs load the encoder from
|
| 194 |
+
`pretrained/monkeyocrv2_as` (see [Pretrained Backbone](#pretrained-backbone)).
|
| 195 |
+
- Every config sets `randomness = dict(seed=42)`; results are selected by the
|
| 196 |
+
best test-set hmean over the training run, evaluated every 20 epochs.
|
| 197 |
+
|
| 198 |
+
## Evaluation
|
| 199 |
+
|
| 200 |
+
```bash
|
| 201 |
+
# single GPU
|
| 202 |
+
python tools/test.py \
|
| 203 |
+
configs/textdet/dbnet/dbnet_mkv2vitae_1200e_totaltext_2gpu_adamw.py \
|
| 204 |
+
model_weight/dbnet_mkv2vitae_totaltext.pth
|
| 205 |
+
|
| 206 |
+
# multi GPU
|
| 207 |
+
bash tools/dist_test.sh \
|
| 208 |
+
configs/textdet/psenet/psenet_mkv2vitae_fpnf_600e_ctw1500_4gpu_adamw.py \
|
| 209 |
+
model_weight/psenet_mkv2vitae_ctw1500.pth 1
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
The evaluation prints `precision / recall / hmean` with the
|
| 213 |
+
`HmeanIOUMetric`, matching the tables above.
|
| 214 |
+
|
| 215 |
+
## Acknowledgements
|
| 216 |
+
|
| 217 |
+
This project builds on [MMOCR](https://github.com/open-mmlab/mmocr),
|
| 218 |
+
[DBNet](https://arxiv.org/abs/1911.08947),
|
| 219 |
+
[PSENet](https://arxiv.org/abs/1806.02559), and
|
| 220 |
+
[oCLIP](https://arxiv.org/abs/2303.06995).
|