File size: 11,600 Bytes
a7258c8
 
 
 
 
123e24a
a4d720a
 
 
 
 
 
 
 
 
 
13b4bab
a4d720a
 
 
 
 
 
 
 
 
a7258c8
821985d
a4d720a
821985d
aae75f0
821985d
aae75f0
 
 
d2bcd0e
aae75f0
 
 
d2bcd0e
a4d720a
d2bcd0e
aae75f0
d2bcd0e
a4d720a
 
aae75f0
 
 
 
 
 
 
a4d720a
 
aae75f0
 
a4d720a
aae75f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d2bcd0e
 
aae75f0
d2bcd0e
a4d720a
d2bcd0e
aae75f0
821985d
aae75f0
821985d
aae75f0
a4d720a
aae75f0
 
85f2557
aae75f0
85f2557
aae75f0
a4d720a
aae75f0
 
85f2557
aae75f0
821985d
aae75f0
85f2557
aae75f0
a4d720a
aae75f0
 
 
 
 
 
 
 
 
 
 
85f2557
a4d720a
85f2557
aae75f0
a4d720a
aae75f0
821985d
a4d720a
 
821985d
aae75f0
a4d720a
aae75f0
fd26334
aae75f0
a4d720a
 
aae75f0
a4d720a
 
fd26334
aae75f0
fd26334
 
aae75f0
a4d720a
fd26334
a4d720a
 
aae75f0
a4d720a
 
 
 
 
 
 
 
fd26334
 
aae75f0
fd26334
aae75f0
fd26334
aae75f0
a4d720a
 
 
 
 
aae75f0
a4d720a
 
 
 
aae75f0
a4d720a
 
 
aae75f0
a4d720a
 
aae75f0
a4d720a
 
 
aae75f0
a4d720a
aae75f0
a4d720a
 
 
 
 
 
 
 
 
aae75f0
a4d720a
 
 
 
 
 
 
 
 
 
 
aae75f0
a4d720a
 
aae75f0
 
 
 
 
a4d720a
aae75f0
fd26334
 
aae75f0
fd26334
a4d720a
aae75f0
 
a4d720a
 
aae75f0
fd26334
 
a4d720a
fd26334
aae75f0
fd26334
aae75f0
 
 
 
821985d
aae75f0
feef991
aae75f0
a4d720a
aae75f0
 
 
 
feef991
a4d720a
feef991
aae75f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feef991
a4d720a
aae75f0
 
feef991
aae75f0
feef991
a4d720a
 
aae75f0
a4d720a
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
---
license: apache-2.0
language:
- zh
- en
- ja
- ko
- fr
- de
- es
- ru
- ar
- hi
- th
- el
library_name: pytorch
tags:
- ocr
- text-detection
- text-recognition
- paddleocr
- pp-ocrv5
- multilingual
- svtr
- db
pipeline_tag: image-to-text
---

# PP-OCRv5 PyTorch Model Zoo

PyTorch weights (**safetensors** format) for the full **PP-OCRv5** family, converted bit-exactly from the official PaddlePaddle `.pdparams` dynamic-graph weights β€” inference outputs are **identical to the original PaddleOCR** down to float32 precision.

- **Text Detection**: 2 models (mobile / server)
- **Text Recognition (base)**: 2 models covering Simplified Chinese / Traditional Chinese / English / Japanese
- **Text Recognition (multilingual)**: 11 models covering **100+ languages** (Korean, French, German, Russian, Arabic, Devanagari, Thai, Greek, Tamil, Telugu, etc.)

> This repo contains **weights + configs + dictionaries only**, not inference code. For inference, use [PaddleOCR2Pytorch](https://github.com/frotms/PaddleOCR2Pytorch), or follow the "Custom Python Inference" section below.
>
> Also available: [README_zh.md](./README_zh.md) (δΈ­ζ–‡η‰ˆ).

---

## Repository Layout

```
.
β”œβ”€β”€ README.md / README_zh.md
β”œβ”€β”€ LICENSE                                                 # Apache 2.0
β”œβ”€β”€ config.json                                             # Repo metadata + model index
β”‚
β”œβ”€β”€ ptocr_v5_*.safetensors                                  # 15 PP-OCRv5 weights at root (stable URLs)
β”œβ”€β”€ ptocr_v5_server_{det,rec}.pth                           # Legacy pth copies of V5 server (kept)
β”‚
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ det/PP-OCRv5/
β”‚   β”‚   β”œβ”€β”€ PP-OCRv5_mobile_det.yml
β”‚   β”‚   └── PP-OCRv5_server_det.yml
β”‚   └── rec/PP-OCRv5/
β”‚       β”œβ”€β”€ PP-OCRv5_mobile_rec.yml                         # zh / zh-Hant / en / ja
β”‚       β”œβ”€β”€ PP-OCRv5_server_rec.yml
β”‚       └── multi_language/                                 # 11 multilingual rec yamls
β”‚           β”œβ”€β”€ en_PP-OCRv5_mobile_rec.yaml
β”‚           β”œβ”€β”€ korean_PP-OCRv5_mobile_rec.yml
β”‚           β”œβ”€β”€ latin_PP-OCRv5_mobile_rec.yml               # French / German / Spanish / ...  (40+ Latin-script)
β”‚           β”œβ”€β”€ eslav_PP-OCRv5_mobile_rec.yml               # Russian / Belarusian / Ukrainian
β”‚           β”œβ”€β”€ cyrillic_PP-OCRv5_mobile_rec.yaml           # 33 Cyrillic-script languages
β”‚           β”œβ”€β”€ arabic_PP-OCRv5_mobile_rec.yaml             # Arabic / Persian / Uyghur / Urdu / ...
β”‚           β”œβ”€β”€ devanagari_PP-OCRv5_mobile_rec.yaml         # Hindi / Marathi / Nepali / Sanskrit / ...
β”‚           β”œβ”€β”€ th_PP-OCRv5_mobile_rec.yaml                 # Thai
β”‚           β”œβ”€β”€ el_PP-OCRv5_mobile_rec.yaml                 # Greek
β”‚           β”œβ”€β”€ ta_PP-OCRv5_mobile_rec.yaml                 # Tamil
β”‚           └── te_PP-OCRv5_mobile_rec.yaml                 # Telugu
β”‚
β”œβ”€β”€ dicts/                                                  # Character set dictionaries (required for rec)
β”‚   β”œβ”€β”€ ppocrv5_dict.txt                                    # base (zh / zh-Hant / en / ja)
β”‚   └── ppocrv5_<lang>_dict.txt                             # 11 multilingual dicts
β”‚
└── legacy/                                                 # Older PP-OCR v2/v3/v4 weights (kept for back-compat)
    β”œβ”€β”€ ch_ptocr_mobile_v2.0_cls_infer.pth
    β”œβ”€β”€ ch_ptocr_v4_det_infer.pth
    β”œβ”€β”€ ch_ptocr_v4_rec_infer.pth
    β”œβ”€β”€ en_ptocr_v3_det_infer.pth
    └── en_ptocr_v4_rec_infer.pth
```

> All rec yamls use relative `character_dict_path: ./dicts/...`. After `git clone` or `snapshot_download`, paths resolve correctly with **no modification required**.

---

## Model Catalog

### Text Detection

| Weight | Config | Use case | Size |
|---|---|---|---|
| `ptocr_v5_mobile_det.safetensors` | `configs/det/PP-OCRv5/PP-OCRv5_mobile_det.yml` | Mobile / CPU-friendly | ~14 MB |
| `ptocr_v5_server_det.safetensors` | `configs/det/PP-OCRv5/PP-OCRv5_server_det.yml` | Server / high-accuracy | ~101 MB |

### Text Recognition (Base)

| Weight | Config | Languages | Size |
|---|---|---|---|
| `ptocr_v5_mobile_rec.safetensors` | `configs/rec/PP-OCRv5/PP-OCRv5_mobile_rec.yml` | Simplified / Traditional Chinese, English, Japanese | ~31 MB |
| `ptocr_v5_server_rec.safetensors` | `configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml` | same as above, higher accuracy | ~128 MB |

### Text Recognition (Multilingual)

All multilingual rec models share the same architecture (`SVTR_LCNet` + `PPLCNetV3`); they differ only by character dictionary. File size 23–28 MB each.

| Weight | Supported languages |
|---|---|
| `ptocr_v5_en_mobile_rec.safetensors` | English (dedicated model optimized for English-only scenarios) |
| `ptocr_v5_korean_mobile_rec.safetensors` | Korean, English |
| `ptocr_v5_latin_mobile_rec.safetensors` | French, German, Spanish, Italian, Portuguese, Dutch, Swedish, Danish, Norwegian, Finnish, Polish, Czech, Turkish, Vietnamese, ... (40+ Latin-script) |
| `ptocr_v5_eslav_mobile_rec.safetensors` | Russian, Belarusian, Ukrainian, English |
| `ptocr_v5_cyrillic_mobile_rec.safetensors` | 33 Cyrillic-script languages (Russian, Serbian-Cyrillic, Bulgarian, Mongolian, Kazakh, ...) |
| `ptocr_v5_arabic_mobile_rec.safetensors` | Arabic, Persian, Uyghur, Urdu, Pashto, Sindhi, ... |
| `ptocr_v5_devanagari_mobile_rec.safetensors` | 14 Devanagari-script languages (Hindi, Marathi, Nepali, Sanskrit, ...) |
| `ptocr_v5_th_mobile_rec.safetensors` | Thai, English |
| `ptocr_v5_el_mobile_rec.safetensors` | Greek, English |
| `ptocr_v5_ta_mobile_rec.safetensors` | Tamil, English |
| `ptocr_v5_te_mobile_rec.safetensors` | Telugu, English |

---

## Quick Start

### Download Weights

```python
from huggingface_hub import snapshot_download, hf_hub_download

# Option 1: download the whole repo (weights + configs + dicts + README)
repo_dir = snapshot_download(repo_id="JoyCN/PaddleOCR-Pytorch")
print("downloaded to:", repo_dir)

# Option 2: fetch a single weight file
weight_path = hf_hub_download(
    repo_id="JoyCN/PaddleOCR-Pytorch",
    filename="ptocr_v5_korean_mobile_rec.safetensors",
)
```

### Inference via PaddleOCR2Pytorch (Recommended)

```bash
# 1. clone the inference code repo
git clone https://github.com/frotms/PaddleOCR2Pytorch
cd PaddleOCR2Pytorch
pip install torch safetensors pyyaml shapely pyclipper opencv-python pillow scikit-image

# 2. Assume you ran snapshot_download above into /path/to/hf_repo
python tools/infer/predict_rec.py \
  --image_dir doc/imgs_words/korean/1.jpg \
  --rec_algorithm SVTR_LCNet \
  --rec_model_path /path/to/hf_repo/ptocr_v5_korean_mobile_rec.safetensors \
  --rec_yaml_path  /path/to/hf_repo/configs/rec/PP-OCRv5/multi_language/korean_PP-OCRv5_mobile_rec.yml \
  --rec_image_shape "3,48,320" \
  --rec_char_dict_path /path/to/hf_repo/dicts/ppocrv5_korean_dict.txt \
  --use_gpu False
```

> PaddleOCR2Pytorch `base_ocr_v20.py` auto-detects `.safetensors` vs `.pth` by extension (backward compatible).

### Custom Python Inference

A minimal skeleton showing how to load the weights and run a forward pass. You still need the network definitions from the PaddleOCR2Pytorch `pytorchocr/modeling/` package.

```python
import sys, numpy as np, cv2, torch, yaml
from safetensors.torch import load_file

# Requires https://github.com/frotms/PaddleOCR2Pytorch on PYTHONPATH
sys.path.insert(0, "/path/to/PaddleOCR2Pytorch")
from pytorchocr.modeling.architectures.base_model import BaseModel
from pytorchocr.postprocess import build_post_process

HF_REPO = "/path/to/hf_repo"   # the path returned by snapshot_download
yml_path    = f"{HF_REPO}/configs/rec/PP-OCRv5/multi_language/korean_PP-OCRv5_mobile_rec.yml"
weight_path = f"{HF_REPO}/ptocr_v5_korean_mobile_rec.safetensors"

# 1. load config + dictionary
with open(yml_path, encoding="utf-8") as f:
    cfg = yaml.safe_load(f)
dict_path = cfg["Global"]["character_dict_path"]          # './dicts/ppocrv5_korean_dict.txt'
dict_abs  = f"{HF_REPO}/{dict_path.lstrip('./')}"
with open(dict_abs, encoding="utf-8") as f:
    chars = [l.strip("\n\r") for l in f]
n_char = len(chars) + 2                                   # +1 blank, +1 space (if use_space_char)

# 2. build network + load weights (safetensors = zero-code-exec, mmap-fast)
cfg["Architecture"]["Head"]["out_channels_list"] = {
    "CTCLabelDecode": n_char,
    "SARLabelDecode": n_char + 2,
    "NRTRLabelDecode": n_char + 3,
}
net = BaseModel(cfg["Architecture"], out_channels=n_char)
net.load_state_dict(load_file(weight_path, device="cpu"))
net.eval()

# 3. preprocess (resize to [3, 48, 320], normalize to [-1, 1])
img = cv2.imread("input_word.jpg")
h, w = img.shape[:2]
ratio = w / h
tw = min(int(48 * ratio), 320)
img = cv2.resize(img, (tw, 48))
canvas = np.zeros((48, 320, 3), dtype=np.uint8)
canvas[:, :tw] = img
x = canvas.astype(np.float32).transpose(2, 0, 1) / 255.0
x = (x - 0.5) / 0.5
x = torch.from_numpy(x).unsqueeze(0)

# 4. forward + CTC decode
with torch.no_grad():
    logits = net(x)
post_op = build_post_process({
    "name": "CTCLabelDecode",
    "character_dict_path": dict_abs,
    "use_space_char": True,
})
result = post_op(logits)
print("prediction:", result)          # e.g. [('λ°”νƒ•μœΌλ‘œ', 0.9998)]
```

### Runtime Dependencies

```
torch        >= 1.13
safetensors  >= 0.4
numpy, pillow, opencv-python
pyyaml, shapely, pyclipper
scikit-image                # required by det post-processing
```

---

## Conversion & Verification

- **Source weights**: official PaddlePaddle `.pdparams` from  
  `https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/`
- **Converter**: [PaddleOCR2Pytorch](https://github.com/frotms/PaddleOCR2Pytorch) β€” scripts `converter/ppocr_v5_det_converter.py` / `converter/ppocr_v5_rec_converter.py`
- **Verification**: end-to-end inference was run on macOS Apple Silicon (M-series) CPU; multilingual rec outputs are **bit-exact** with the original PaddleOCR `.pdparams` (float32 values match to 8 decimal places).

Sample inference results (CPU, < 0.7 s / image):

| Sample | Prediction | Confidence |
|---|---|---|
| Chinese `word_1.jpg` | ιŸ©ε›½ε°ι¦† | 0.99797755 |
| Korean `korean/1.jpg` | λ°”νƒ•μœΌλ‘œ | 0.99977183 |
| French `french/1.jpg` | de l'amendement, | 0.99656343 |
| Arabic `arabic/ar_1.jpg` | Ψ§Ω„ΩƒΩŠΨ΅ΩŠΨ§ΩˆΩŠ | 0.68281130 |

---

## Legacy Files (`legacy/`)

Older PP-OCR (v2 / v3 / v4) checkpoints previously at the repo root have been **moved into `legacy/`** for clarity. They are still present and continue to work β€” just add the `legacy/` prefix to your path.

If you were previously using any of these URLs at the root:

```
legacy/ch_ptocr_mobile_v2.0_cls_infer.pth
legacy/ch_ptocr_v4_det_infer.pth
legacy/ch_ptocr_v4_rec_infer.pth
legacy/en_ptocr_v3_det_infer.pth
legacy/en_ptocr_v4_rec_infer.pth
```

The 15 PP-OCRv5 safetensors files **remain at the repo root** β€” their URLs did not change.

---

## License & Credits

- **License**: Apache License 2.0
- Weights originate from [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) by the PaddlePaddle team (Apache 2.0).
- Converted with [PaddleOCR2Pytorch](https://github.com/frotms/PaddleOCR2Pytorch) (Apache 2.0).

If this repo helps you, please also star both of those original projects.

---

## Citation

```bibtex
@misc{pp_ocrv5_pytorch_joycn_2025,
  title        = {PP-OCRv5 PyTorch Model Zoo},
  author       = {JoyCN},
  howpublished = {\url{https://huggingface.co/JoyCN/PaddleOCR-Pytorch}},
  year         = {2025}
}
```