A BiLSTM neural network for recognizing handwritten chess moves from scoresheet images.
Source du modèle
Description de la source
A BiLSTM neural network for recognizing handwritten chess moves from scoresheet images.
This model recognizes handwritten chess moves in Standard Algebraic Notation (SAN) from cropped move-box images extracted from chess scoresheets.
Sources
1 sourceVérifié 10 sept.
Artefacts du modèle
3 artefactsExtraits de sources
2 extraits| File | Size | Use Case |
|---|---|---|
chess_ocr.onnx | 41 MB | Browser inference (ONNX Runtime Web) |
chess_ocr_v47_complete.pth | ~47 MB | Python/PyTorch inference |
best_chess_ocr_v47.pth | ~127 MB | Resume training (includes optimizer state) |
import * as ort from 'onnxruntime-web';
// Load model from HuggingFace
const modelUrl = 'https://huggingface.co/GerhardTrippen/chess-ocr-bilstm/resolve/main/chess_ocr.onnx';
const session = await ort.InferenceSession.create(modelUrl);
// Preprocess image to 64x256 grayscale, normalize to [-1, 1]
const inputTensor = new ort.Tensor('float32', imageData, [1, 1, 64, 256]);
// Run inference
const results = await session.run({ input: inputTensor });
const output = results.output.data;
// Decode with CTC (greedy or beam search)
const move = ctcDecode(output, charset);
import torch
from PIL import Image
import numpy as np
# Load model
checkpoint = torch.load('chess_ocr_v47_complete.pth', map_location='cpu')
model = ChessOCRModel() # See training notebook for architecture
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
idx_to_char = checkpoint['idx_to_char']
# Preprocess: resize to 256x64, grayscale, normalize
image = Image.open('move_cell.png').convert('L')
image = image.resize((256, 64))
img_array = np.array(image, dtype=np.float32)
img_array = (img_array / 255.0 - 0.5) / 0.5 # Normalize to [-1, 1]
tensor = torch.FloatTensor(img_array).unsqueeze(0).unsqueeze(0)
# Inference
with torch.no_grad():
output = model(tensor)
# CTC greedy decode
predictions = output.argmax(dim=2).squeeze()
move = ''.join([idx_to_char[idx.item()] for idx in predictions if idx.item() != 0])
Trained on the HCS (Handwritten Chess Scoresheet) dataset.
See BiLSTM_v7.ipynb for the complete training code.
Training configuration:
Key differences from original Eicher et al. approach:
This model implements the architecture described in:
Eicher, O., Farmer, D., Li, Y., & Majid, N. (2021). "Handwritten Chess Scoresheet Recognition Using a Convolutional BiLSTM Network." ICDAR 2021 Workshops, pp. 245-259.
DOI: 10.1007/978-3-030-86198-8_18
Majid, N., Eicher, O. (2022). "Digitization of Handwritten Chess Scoresheets with a BiLSTM Network." J. Imaging 2022, 8, 31.
DOI: 10.3390/jimaging8020031
Dataset:
MIT License - Free for personal and commercial use.
Trained and uploaded by Gerhard Trippen (2025).
@misc{trippen2025chessocr,
author = {Trippen, Gerhard},
title = {Chess OCR BiLSTM: Handwritten Chess Scoresheet Recognition},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/GerhardTrippen/chess-ocr-bilstm}
}
chess_ocr.onnx
onnx · 41,3 MB · SHA-256 79b59131dc92…6953 · Hugging Face
--- license: mit language: - en tags: - chess - ocr - handwriting-recognition - bilstm - ctc - pytorch - onnx datasets: - BenjaminKost/processed_hcs metrics: - accuracy pipeline_tag: image-to-text --- # Chess OCR BiLSTM A BiLSTM neural network for recognizing handwritten chess moves from scoresheet images. ## Model Description This model recognizes handwritten chess moves in Standard Algebraic Notation (SAN) from cropped move-box images extracted from chess scoresheets. - **Architecture:** CNN frontend + Bidirectional LSTM + CTC loss - **Input:** 64×256 grayscale image, normalized to [-1, 1] - **Output:** Chess move string (e.g., "e4", "Nf3", "O-O", "Qxd7+") - **Character set:** 28 classes (blank + K, Q, R, B, N, a-h, 1-8, x, +, #, =, O, -) ## Model Variants | File | Size | Use Case | |------|------|----------| | `chess_ocr.onnx` | 41 MB | Browser inference (ONNX Runtime Web) | | `chess_ocr_v47_complete.pth` | ~47 MB | Python/PyTorch inference | | `best_chess_ocr_v47.pth` | ~127 MB | Resume training (includes optimizer state) | ## Usage (Browser - ONNX Runtime Web) ```javascript import * as ort from 'onnxruntime-web'; // Load model from HuggingFace const modelUrl = 'https://huggingface.co/GerhardTrippen/chess-ocr-bilstm/resolve/main/chess_ocr.onnx'; const session = await ort.InferenceSession.create(modelUrl); // Preprocess image to 64x256 grayscale, normalize to [-1, 1] const inputTensor = new ort.Tensor('float32', imageData, [1, 1, 64, 256]); // Run inference const results = await session.run({ input: inputTensor }); const output = results.output.data; // Decode with CTC (greedy or beam search) const move = ctcDecode(output, charset); ``` ## Usage (Python/PyTorch) ```python import torch from PIL import Image import numpy as np # Load model checkpoint = torch.load('chess_ocr_v47_complete.pth', map_location='cpu') model = ChessOCRModel() # See training notebook for architecture model.load_state_dict(checkpoint['model_state_dict']) model.eval() idx_to_char = checkpoint['idx_to_char'] # Preprocess: resize to 256x64, grayscale, normalize image = Image.open('move_cell.png').convert('L') image = image.resize((256, 64)) img_array = np.array(image, dtype=np.float32) img_array = (img_array / 255.0 - 0.5) / 0.5 # Normalize to [-1, 1] tensor = torch.FloatTensor(img_array).unsqueeze(0).unsqueeze(0) # Inference with torch.no_grad(): outpu...
Source context: 0 downloads · 0 likes · Pipeline image-to-text · Repo GerhardTrippen/chess-ocr-bilstm