Downloads · 30 days
0
GerhardTrippen/chess-ocr-bilstm
chess-ocr-bilstm is a image-to-text model from GerhardTrippen. Use it when you need a caption or text from an image. The card lists the license as mit.
A BiLSTM neural network for recognizing handwritten chess moves from scoresheet images.
Downloads · 30 days
0
Access
Public
Updated Jan 26, 2026
Repo size
216 MB
Likes
0
Public
Click a slice to open those files.
.pth173 MB · 80%
From the Hugging Face model README
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.
| 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}
}