Skip to main content

CNN-based chess piece classifier

Project description

Chess CV

GitHub release PyPI Python 3.13+ License: MIT llms.txt

Model Architecture

CNN-based chess piece classifier


A machine learning project that trains lightweight CNNs (156k parameters each) from scratch to classify chess pieces and arrow annotations from 32×32 pixel square images. The project includes two specialized models:

  • Pieces Model: Classifies 13 classes (6 white pieces, 6 black pieces, empty squares) for board state recognition and FEN generation
  • Arrows Model: Classifies 49 classes representing arrow overlay patterns for detecting and reconstructing chess analysis annotations

Both models are trained on synthetic data generated by combining 55 board styles from chess.com and lichess with piece sets and arrow overlays, achieving robust recognition across various visual styles.

⚡️ Quick Start

pip install chess-cv

Then use pre-trained models:

from chess_cv.model import SimpleCNN
from huggingface_hub import hf_hub_download

# Load pre-trained model
model_path = hf_hub_download(repo_id="S1M0N38/chess-cv", filename="pieces.safetensors")
model = SimpleCNN(num_classes=13)
model.load_weights(model_path)

# Make predictions
predictions = model(image_tensor)

✨ Features

Lightweight Architecture

  • 156k parameter CNN optimized for 32×32px images
  • MLX framework for efficient training
  • Aggressive data augmentation for robust generalization

Complete Pipeline

  • Synthetic data generation from board/piece combinations
  • Training with early stopping and checkpointing
  • Comprehensive evaluation with confusion matrices
  • Optional Weights & Biases integration for experiment tracking
  • Hugging Face Hub deployment for model sharing

🎯 Models

This project includes two specialized models for chess board analysis:

♟️ Pieces Model (pieces.safetensors)

Classifies chess square images into 13 classes: 6 white pieces (wP, wN, wB, wR, wQ, wK), 6 black pieces (bP, bN, bB, bR, bQ, bK), and empty squares (xx). Designed for board state recognition and FEN generation.

Training: ~93,000 synthetic images with aggressive augmentation (arrow overlays, flips, rotation, color jitter)

Performance:

Dataset Accuracy F1-Score (Macro)
Test Data 99.94% 99.94%
S1M0N38/chess-cv-openboard * - 98.26%
S1M0N38/chess-cv-chessvision * - 83.47%

* Dataset with unbalanced class distribution (e.g. many more samples for empty square class), so accuracy is not representative.

↗ Arrows Model (arrows.safetensors)

Classifies chess square images into 49 classes representing arrow overlay patterns: 20 arrow heads, 12 tails, 8 middle segments, 4 corners, and empty squares. Enables detection and reconstruction of arrow annotations in chess interfaces. The NSEW naming (North/South/East/West) indicates arrow orientation, with corners handling knight-move arrow patterns.

Training: ~3.14M synthetic images (20 epochs, batch size 128) with conservative augmentation (no flips/rotation to preserve arrow directionality)

Performance:

Dataset Accuracy F1-Score (Macro)
Test Data (synthetic) 99.97% 99.97%

Limitation: Single arrow component per square only

📚 Documentation

For detailed documentation, visit s1m0n38.github.io/chess-cv or explore:

License

This project is licensed under the MIT License – see the LICENSE file for details.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chess_cv-0.3.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chess_cv-0.3.0-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file chess_cv-0.3.0.tar.gz.

File metadata

  • Download URL: chess_cv-0.3.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.0

File hashes

Hashes for chess_cv-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0047c7b5389d90395176ff38d051b74c525c12d78388b878f31007dc7c8d85bb
MD5 c27d8fdd094b7d9694053a132fe1d348
BLAKE2b-256 e9def4d79fb2b83b0db7ff64cb5825d11ba03c74515fffd709cb006023e0b797

See more details on using hashes here.

File details

Details for the file chess_cv-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: chess_cv-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.0

File hashes

Hashes for chess_cv-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08936f1c7003d4defdd6949663d47979221742224cdf839dddf1dd9493245759
MD5 b0e0607fe5b1e68ba8d3277d5d461741
BLAKE2b-256 75dee0d49c9845b2913a8e050a74d78397c8c5f0a91feb56ad1cfb4fe024db6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page