M2key1 commited on
Commit
dabedb6
·
verified ·
1 Parent(s): b2cd95b

Release DeepOCR v3

Browse files
Files changed (4) hide show
  1. README.md +87 -0
  2. deepocr-v3.pt +3 -0
  3. union_bytes_v3.bin +3 -0
  4. union_bytes_v3.dict +261 -0
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: pytorch
4
+ pipeline_tag: image-to-text
5
+ tags:
6
+ - ocr
7
+ - htr
8
+ - handwritten-text-recognition
9
+ - historical-documents
10
+ ---
11
+
12
+ # DeepOCR v3
13
+
14
+ A line-level text recognition model for historical print and handwriting: Fraktur, Antiqua, Kurrent, and medieval and modern Latin script, in one checkpoint. Code, training and architecture: [DeepOCR](https://github.com/m2key1/DeepOCR).
15
+
16
+ ## Files
17
+
18
+ | File | What it is |
19
+ |---|---|
20
+ | `deepocr-v3.pt` | The model weights (EMA), with every architecture setting stored inside |
21
+ | `union_bytes_v3.bin` | Byte-level 6-gram KenLM, fused into the beam search |
22
+ | `union_bytes_v3.dict` | The LM's token list, index-parallel to the model's 261-token byte vocabulary |
23
+
24
+ The LM belongs to this checkpoint. Do not pair it with another one.
25
+
26
+ ## Use
27
+
28
+ ```python
29
+ from pathlib import Path
30
+
31
+ import torch
32
+ from PIL import Image
33
+ import infer
34
+ from infer import load_model, transcribe_beam
35
+
36
+ infer.KENLM_PATH = Path('union_bytes_v3.bin')
37
+ infer.LM_DICT_PATH = Path('union_bytes_v3.dict')
38
+ infer.LM_WEIGHT = 1.0
39
+ infer.BEAM_WIDTH = 10
40
+
41
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
42
+ model, tokenizer = load_model('deepocr-v3.pt', device)
43
+ print(transcribe_beam(model, tokenizer, [Image.open('line.png')], device)[0])
44
+ ```
45
+
46
+ Input is one text line as an RGB image; it is scaled to 256 px high and read up to 6144 px wide. Three flags choose the transcription convention: `long_s` (ſ), `oblique_hyphen` (⸗) and `typographic_punctuation`. Set them in `infer.CONVENTION`; all off by default.
47
+
48
+ The model is also the OCR builtin of [DeepLabel](https://github.com/m2key1/DeepLabel).
49
+
50
+ ## Model
51
+
52
+ 170.5M parameters. A grouped CNN backbone feeds four mixture-of-experts transformer layers (64 experts, 8 active per column, plus one shared expert) and a CTC head over bytes, so it can emit any Unicode character. Trained from scratch.
53
+
54
+ ## Evaluation
55
+
56
+ CER on the held-out validation split, 25,000 lines:
57
+
58
+ | Decoding | CER |
59
+ |---|---|
60
+ | Greedy | 3.68% |
61
+ | Beam 10 | 3.57% |
62
+ | Beam 10 + KenLM, weight 1.0 | 3.03% |
63
+
64
+ ## Training data
65
+
66
+ Public datasets of historical print and handwriting. The language model was built from the same training split.
67
+
68
+ ## Limitations
69
+
70
+ - Reads single lines only; it needs a line detector or segmentation in front of it.
71
+ - Reads best on material like its training data: European print and handwriting from the medieval to the modern period. Accuracy drops on other scripts and unusual hands.
72
+ - The language model favours the training text; for mostly numeric or tabular text, lower `LM_WEIGHT` or decode without it.
73
+
74
+ ## License
75
+
76
+ Apache-2.0.
77
+
78
+ ## Citation
79
+
80
+ ```bibtex
81
+ @software{fleischhacker_deepocr,
82
+ author = {Fleischhacker, David},
83
+ title = {DeepOCR},
84
+ year = {2026},
85
+ url = {https://github.com/m2key1/DeepOCR}
86
+ }
87
+ ```
deepocr-v3.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58eccc0567053e406805e6864ce5055355c3efa43e7f962ff2bb8ff9127deae7
3
+ size 702599699
union_bytes_v3.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fbe2c7c470c0df29ab24e784ca82e80858b8d3a7e87f8e4852ade39fa5a7d92c
3
+ size 85627362
union_bytes_v3.dict ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [BLANK]
2
+ [UNK]
3
+ [PAD]
4
+ [BOS]
5
+ [EOS]
6
+ <tok5>
7
+ <tok6>
8
+ <tok7>
9
+ <tok8>
10
+ <tok9>
11
+ <tok10>
12
+ <tok11>
13
+ <tok12>
14
+ <tok13>
15
+ <tab>
16
+ <nl>
17
+ <tok16>
18
+ <tok17>
19
+ <tok18>
20
+ <tok19>
21
+ <tok20>
22
+ <tok21>
23
+ <tok22>
24
+ <tok23>
25
+ <tok24>
26
+ <tok25>
27
+ <tok26>
28
+ <tok27>
29
+ <tok28>
30
+ <tok29>
31
+ <tok30>
32
+ <tok31>
33
+ <tok32>
34
+ <tok33>
35
+ <tok34>
36
+ <tok35>
37
+ <tok36>
38
+ <space>
39
+ !
40
+ "
41
+ #
42
+ $
43
+ %
44
+ &
45
+ '
46
+ (
47
+ )
48
+ *
49
+ +
50
+ ,
51
+ -
52
+ .
53
+ /
54
+ 0
55
+ 1
56
+ 2
57
+ 3
58
+ 4
59
+ 5
60
+ 6
61
+ 7
62
+ 8
63
+ 9
64
+ :
65
+ ;
66
+ <
67
+ =
68
+ >
69
+ ?
70
+ @
71
+ A
72
+ B
73
+ C
74
+ D
75
+ E
76
+ F
77
+ G
78
+ H
79
+ I
80
+ J
81
+ K
82
+ L
83
+ M
84
+ N
85
+ O
86
+ P
87
+ Q
88
+ R
89
+ S
90
+ T
91
+ U
92
+ V
93
+ W
94
+ X
95
+ Y
96
+ Z
97
+ [
98
+ \
99
+ ]
100
+ ^
101
+ _
102
+ `
103
+ a
104
+ b
105
+ c
106
+ d
107
+ e
108
+ f
109
+ g
110
+ h
111
+ i
112
+ j
113
+ k
114
+ l
115
+ m
116
+ n
117
+ o
118
+ p
119
+ q
120
+ r
121
+ s
122
+ t
123
+ u
124
+ v
125
+ w
126
+ x
127
+ y
128
+ z
129
+ {
130
+ |
131
+ }
132
+ ~
133
+ <tok132>
134
+ <tok133>
135
+ <tok134>
136
+ <tok135>
137
+ <tok136>
138
+ <tok137>
139
+ <tok138>
140
+ <tok139>
141
+ <tok140>
142
+ <tok141>
143
+ <tok142>
144
+ <tok143>
145
+ <tok144>
146
+ <tok145>
147
+ <tok146>
148
+ <tok147>
149
+ <tok148>
150
+ <tok149>
151
+ <tok150>
152
+ <tok151>
153
+ <tok152>
154
+ <tok153>
155
+ <tok154>
156
+ <tok155>
157
+ <tok156>
158
+ <tok157>
159
+ <tok158>
160
+ <tok159>
161
+ <tok160>
162
+ <tok161>
163
+ <tok162>
164
+ <tok163>
165
+ <tok164>
166
+ <nbsp>
167
+ ¡
168
+ ¢
169
+ £
170
+ ¤
171
+ ¥
172
+ ¦
173
+ §
174
+ ¨
175
+ ©
176
+ ª
177
+ «
178
+ ¬
179
+ <tok178>
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
+ ÿ