Views
No views yet
| 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) |
1import * as ort from 'onnxruntime-web';
2
3// Load model from HuggingFace
4const modelUrl = 'https://huggingface.co/GerhardTrippen/chess-ocr-bilstm/resolve/main/chess_ocr.onnx';
5const session = await ort.InferenceSession.create(modelUrl);
6
7// Preprocess image to 64x256 grayscale, normalize to [-1, 1]
8const inputTensor = new ort.Tensor('float32', imageData, [1, 1, 64, 256]);
9
10// Run inference
11const results = await session.run({ input: inputTensor });
12const output = results.output.data;
13
14// Decode with CTC (greedy or beam search)
15const move = ctcDecode(output, charset);1import torch
2from PIL import Image
3import numpy as np
4
5# Load model
6checkpoint = torch.load('chess_ocr_v47_complete.pth', map_location='cpu')
7model = ChessOCRModel() # See training notebook for architecture
8model.load_state_dict(checkpoint['model_state_dict'])
9model.eval()
10
11idx_to_char = checkpoint['idx_to_char']
12
13# Preprocess: resize to 256x64, grayscale, normalize
14image = Image.open('move_cell.png').convert('L')
15image = image.resize((256, 64))
16img_array = np.array(image, dtype=np.float32)
17img_array = (img_array / 255.0 - 0.5) / 0.5 # Normalize to [-1, 1]
18tensor = torch.FloatTensor(img_array).unsqueeze(0).unsqueeze(0)
19
20# Inference
21with torch.no_grad():
22 output = model(tensor)
23
24# CTC greedy decode
25predictions = output.argmax(dim=2).squeeze()
26move = ''.join([idx_to_char[idx.item()] for idx in predictions if idx.item() != 0])BiLSTM_v7.ipynb for the complete training code.1@misc{trippen2025chessocr,
2 author = {Trippen, Gerhard},
3 title = {Chess OCR BiLSTM: Handwritten Chess Scoresheet Recognition},
4 year = {2025},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/GerhardTrippen/chess-ocr-bilstm}
7}