Views
No views yet
| Input Image | Predicted Text | Confidence |
|---|---|---|
![]() | η διαδικασία είναι περίπλοκη | 0.9450 |
![]() | η διαδικασία είναι περίπλοκη | 0.9595 |
![]() | Ο Γιώργος ο Γιάννης (missed the comma) | 0.8893 |
![]() | Ο Γιώργος, ο Γιάννης | 0.9575 |
48px, width padded to 320px with zeros[-1, 1]1pip install onnxruntime pillow numpy
2# For GPU support:
3pip install onnxruntime-gpu pillow numpy1from PIL import Image
2import numpy as np
3import math
4import onnxruntime as ort
5
6def resize_norm_img(img, imgH=48, imgW=320):
7 h, w = img.shape[:2]
8 ratio = w / float(h)
9 resized_w = imgW if math.ceil(imgH * ratio) > imgW else int(math.ceil(imgH * ratio))
10 pil_img = Image.fromarray(img)
11 resized_image = np.array(pil_img.resize((resized_w, imgH), Image.BILINEAR)).astype('float32')
12 resized_image = resized_image.transpose((2, 0, 1)) / 255.0
13 resized_image = (resized_image - 0.5) / 0.5
14 padding_im = np.zeros((3, imgH, imgW), dtype=np.float32)
15 padding_im[:, :, :resized_w] = resized_image
16 return np.expand_dims(padding_im, axis=0)
17
18def load_dict(dict_path):
19 with open(dict_path, "rb") as f:
20 lines = f.readlines()
21 character = [line.decode('utf-8').strip() for line in lines] + [" "]
22 return ['<blank>'] + character
23
24def decode(preds, character):
25 preds_idx = preds.argmax(axis=2)[0]
26 preds_prob = preds.max(axis=2)[0]
27 char_list, conf_list = [], []
28 for i, idx in enumerate(preds_idx):
29 if idx != 0 and not (i > 0 and idx == preds_idx[i - 1]):
30 char_list.append(character[idx])
31 conf_list.append(preds_prob[i])
32 text = ''.join(char_list)
33 confidence = float(np.mean(conf_list)) if conf_list else 0.0
34 return text, confidence
35
36# Load model and dictionary
37session = ort.InferenceSession("model.onnx", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
38characters = load_dict("greek_dict.txt")
39
40# Run on an image
41img = np.array(Image.open("your_image.png").convert("RGB"))
42img_bgr = img[:, :, ::-1] # RGB → BGR
43input_tensor = resize_norm_img(img_bgr)
44
45outputs = session.run(None, {session.get_inputs()[0].name: input_tensor})
46text, confidence = decode(outputs[0], characters)
47
48print(f"Recognized: {text}")
49print(f"Confidence: {confidence:.4f}")| Property | Value |
|---|---|
| Task | Handwritten Greek text recognition |
| Architecture | SVTR_HGNet (PPHGNetV2_B4 backbone + SVTR neck, CTC head) |
| Format | ONNX |
| Input size | 3 × 48 × 320 (C × H × W) |
| Language | Greek (el) |
| Runtime | ONNX Runtime (CPU & CUDA) |
├── model.onnx # ONNX model weights
├── greek_dict.txt # Greek character dictionary
├── inference.py # Ready-to-run inference script
└── test.png # Sample test image1@misc{handwritten-greek-ocr,
2 title = {Handwritten Greek OCR},
3 author = {Iordanis Sapidis},
4 year = {2026},
5 url = {https://huggingface.co/iordanissap/handwritten-greek-ocr}
6}