phucsd commited on
Commit
a42bbb0
·
verified ·
1 Parent(s): 019892c

feat(ocr): integrate dedicated Vietnamese PP-OCRv5 model and streamline dropdown

Browse files
.gitattributes CHANGED
@@ -324,3 +324,4 @@ ocr-studio/data/output/rec_cham_inference_v24/inference.pdmodel filter=lfs diff=
324
  ocr-studio/data/output/rec_cham_inference_v24/inference.pdiparams.info filter=lfs diff=lfs merge=lfs -text
325
 
326
  ocr-studio/data/output/ch_PP-OCRv4_det_cham_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
 
 
324
  ocr-studio/data/output/rec_cham_inference_v24/inference.pdiparams.info filter=lfs diff=lfs merge=lfs -text
325
 
326
  ocr-studio/data/output/ch_PP-OCRv4_det_cham_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
327
+ ocr-studio/data/output/rec_vietnamese_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
ocr-studio/app.py CHANGED
@@ -194,7 +194,7 @@ def get_ocr_model(version):
194
  if version in ocr_models:
195
  return ocr_models[version]
196
 
197
- if version in ['vi', 'en', 'fr', 'japan']:
198
  ocr_model = OfficialPaddleOCRWrapper(lang=version)
199
  ocr_models[version] = ocr_model
200
  return ocr_model
@@ -209,14 +209,40 @@ def get_ocr_model(version):
209
  from tools.infer.predict_rec import TextRecognizer
210
  import tools.infer.utility as utility
211
 
212
- model_dir = os.path.join(PROJECT_ROOT, "data", "output", f"rec_cham_inference_{version}")
213
- dict_path = os.path.join(PROJECT_ROOT, "data", f"cham_dict_{version}.txt")
214
-
215
- if not os.path.exists(model_dir):
216
- # Fallback to Golden Baseline v23 if version-specific folder is missing
217
- model_dir = os.path.join(PROJECT_ROOT, "data", "output", "rec_cham_inference_v23")
218
- if not os.path.exists(dict_path):
219
- dict_path = os.path.join(PROJECT_ROOT, "data", "cham_dict_v23.txt")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  sys_argv_backup = sys.argv
222
  sys.argv = [sys.argv[0]]
 
194
  if version in ocr_models:
195
  return ocr_models[version]
196
 
197
+ if version in ['en', 'fr', 'japan']:
198
  ocr_model = OfficialPaddleOCRWrapper(lang=version)
199
  ocr_models[version] = ocr_model
200
  return ocr_model
 
209
  from tools.infer.predict_rec import TextRecognizer
210
  import tools.infer.utility as utility
211
 
212
+ if version == 'vi':
213
+ model_dir = os.path.join(PROJECT_ROOT, "data", "output", "rec_vietnamese_infer")
214
+ dict_path = os.path.join(PROJECT_ROOT, "data", "vietnamese_dict.txt")
215
+ model_ready = os.path.exists(os.path.join(model_dir, "inference.pdiparams")) and os.path.exists(dict_path)
216
+ if not model_ready:
217
+ try:
218
+ print(f"📥 Downloading dedicated Vietnamese OCR model to {model_dir}...")
219
+ os.makedirs(model_dir, exist_ok=True)
220
+ import urllib.request
221
+ base_url = "https://huggingface.co/anbeo2004/paddleocr-v5-rec-vi-custom/resolve/main/"
222
+ dl_files = {
223
+ "custom_dict.txt": dict_path,
224
+ "inference.json": os.path.join(model_dir, "inference.json"),
225
+ "inference.yml": os.path.join(model_dir, "inference.yml"),
226
+ "inference.pdiparams": os.path.join(model_dir, "inference.pdiparams")
227
+ }
228
+ for fname, ftarget in dl_files.items():
229
+ if not os.path.exists(ftarget):
230
+ urllib.request.urlretrieve(base_url + fname, ftarget)
231
+ print("✅ Downloaded Vietnamese OCR model successfully.")
232
+ except Exception as e:
233
+ print(f"⚠️ Failed to auto-download Vietnamese model: {e}")
234
+ ocr_model = OfficialPaddleOCRWrapper(lang='vi')
235
+ ocr_models[version] = ocr_model
236
+ return ocr_model
237
+ else:
238
+ model_dir = os.path.join(PROJECT_ROOT, "data", "output", f"rec_cham_inference_{version}")
239
+ dict_path = os.path.join(PROJECT_ROOT, "data", f"cham_dict_{version}.txt")
240
+
241
+ if not os.path.exists(model_dir):
242
+ # Fallback to Golden Baseline v23 if version-specific folder is missing
243
+ model_dir = os.path.join(PROJECT_ROOT, "data", "output", "rec_cham_inference_v23")
244
+ if not os.path.exists(dict_path):
245
+ dict_path = os.path.join(PROJECT_ROOT, "data", "cham_dict_v23.txt")
246
 
247
  sys_argv_backup = sys.argv
248
  sys.argv = [sys.argv[0]]
ocr-studio/data/output/rec_vietnamese_infer/inference.json ADDED
The diff for this file is too large to render. See raw diff
 
ocr-studio/data/output/rec_vietnamese_infer/inference.pdiparams ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb929c47e349f528c6ff7e00d67b101bf7bb7654dffb5d18ac4156550841ebd3
3
+ size 75601159
ocr-studio/data/output/rec_vietnamese_infer/inference.yml ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Global:
2
+ model_name: PP-OCRv5_server_rec
3
+ Hpi:
4
+ backend_configs:
5
+ paddle_infer:
6
+ trt_dynamic_shapes: &id001
7
+ x:
8
+ - - 1
9
+ - 3
10
+ - 48
11
+ - 160
12
+ - - 1
13
+ - 3
14
+ - 48
15
+ - 320
16
+ - - 8
17
+ - 3
18
+ - 48
19
+ - 3200
20
+ tensorrt:
21
+ dynamic_shapes: *id001
22
+ PreProcess:
23
+ transform_ops:
24
+ - DecodeImage:
25
+ channel_first: false
26
+ img_mode: BGR
27
+ - MultiLabelEncode:
28
+ gtc_encode: NRTRLabelEncode
29
+ - RecResizeImg:
30
+ image_shape:
31
+ - 3
32
+ - 48
33
+ - 512
34
+ - KeepKeys:
35
+ keep_keys:
36
+ - image
37
+ - label_ctc
38
+ - label_gtc
39
+ - length
40
+ - valid_ratio
41
+ PostProcess:
42
+ name: CTCLabelDecode
43
+ character_dict:
44
+ - '!'
45
+ - '"'
46
+ - '%'
47
+ - '&'
48
+ - ''''
49
+ - (
50
+ - )
51
+ - ','
52
+ - '-'
53
+ - .
54
+ - /
55
+ - '0'
56
+ - '1'
57
+ - '2'
58
+ - '3'
59
+ - '4'
60
+ - '5'
61
+ - '6'
62
+ - '7'
63
+ - '8'
64
+ - '9'
65
+ - ':'
66
+ - ;
67
+ - '?'
68
+ - A
69
+ - B
70
+ - C
71
+ - D
72
+ - E
73
+ - F
74
+ - G
75
+ - H
76
+ - I
77
+ - J
78
+ - K
79
+ - L
80
+ - M
81
+ - N
82
+ - O
83
+ - P
84
+ - Q
85
+ - R
86
+ - S
87
+ - T
88
+ - U
89
+ - V
90
+ - W
91
+ - X
92
+ - Y
93
+ - Z
94
+ - '['
95
+ - ']'
96
+ - _
97
+ - a
98
+ - b
99
+ - c
100
+ - d
101
+ - e
102
+ - f
103
+ - g
104
+ - h
105
+ - i
106
+ - j
107
+ - k
108
+ - l
109
+ - m
110
+ - n
111
+ - o
112
+ - p
113
+ - q
114
+ - r
115
+ - s
116
+ - t
117
+ - u
118
+ - v
119
+ - w
120
+ - x
121
+ - y
122
+ - z
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
+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
54
+ a
55
+ b
56
+ c
57
+ d
58
+ e
59
+ f
60
+ g
61
+ h
62
+ i
63
+ j
64
+ k
65
+ l
66
+ m
67
+ n
68
+ o
69
+ p
70
+ q
71
+ r
72
+ s
73
+ t
74
+ u
75
+ v
76
+ w
77
+ x
78
+ y
79
+ z
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
+ ỹ
ocr-studio/index.html CHANGED
@@ -1254,19 +1254,13 @@
1254
  <div class="model-picker-wrap" title="Select neural OCR recognition architecture">
1255
  <span class="model-picker-label">Model:</span>
1256
  <select id="model-select" class="model-select-compact" onchange="updateModelBadge()">
1257
- <optgroup label="Paleographic Cham Models (Custom Fine-Tuned)">
1258
- <option value="v24" selected>Version 24 (Validated Baseline — Verse-Numeral & Noise-Resilient SVTR)</option>
1259
- <option value="v23">Version 23 (Golden Baseline — Visual Order SVTR)</option>
1260
- <option value="v22">Version 22 (Legacy Fallback Baseline)</option>
1261
  </optgroup>
1262
- <optgroup label="Multilingual Baselines (PaddleOCR PP-OCRv4)">
1263
- <option value="vi">Vietnamese (Latin)</option>
1264
- <option value="en">English (Latin)</option>
1265
- <option value="fr">French (Latin)</option>
1266
- <option value="japan">Japanese (CJK)</option>
1267
- </optgroup>
1268
- <optgroup label="Autonomous Routing">
1269
- <option value="auto">Adaptive Dual-Engine (Cham & Vietnamese)</option>
1270
  </optgroup>
1271
  </select>
1272
  </div>
 
1254
  <div class="model-picker-wrap" title="Select neural OCR recognition architecture">
1255
  <span class="model-picker-label">Model:</span>
1256
  <select id="model-select" class="model-select-compact" onchange="updateModelBadge()">
1257
+ <optgroup label="Paleographic Cham Models">
1258
+ <option value="v24" selected>Cham V24 (Recommended — Logical Order)</option>
1259
+ <option value="v23">Cham V23 (Visual Order Baseline)</option>
 
1260
  </optgroup>
1261
+ <optgroup label="Bilingual & Modern Text">
1262
+ <option value="auto">Auto Dual-Engine (Cham & Vietnamese)</option>
1263
+ <option value="vi">Vietnamese (Fine-Tuned PP-OCRv5)</option>
 
 
 
 
 
1264
  </optgroup>
1265
  </select>
1266
  </div>