Skip to main content

CNN-based chess piece classifier

Project description

Chess CV

GitHub release PyPI Python 3.13+ License: MIT

Model Architecture

CNN-based chess piece classifier


A machine learning project that trains a lightweight CNN (156k parameters) from scratch to classify chess pieces from 32×32 pixel square images. The model achieves ~99.85% accuracy on synthetic training data generated by combining 55 board styles (256×256px) with 64 piece sets (32×32px) from chess.com and lichess.

By rendering pieces onto different board backgrounds and extracting individual squares, the model learns robust piece recognition across various visual styles.

Dataset Accuracy F1-Score (Macro)
Test Data 99.85% 99.89%
S1M0N38/chess-cv-openboard -[^1] 95.78%

⚡️ 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="best_model.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
  • 13-class classification (6 white pieces, 6 black pieces, 1 empty)
  • 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

📚 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.


[^1]: OpenBoard has an unbalanced class distribution (many more samples for empty square class), so accuracy is not representative.

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.2.0.tar.gz (3.3 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.2.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chess_cv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b723f503ae372987f3433346b5e54d976a813507c408a011b50594a2b8e8bf08
MD5 80ab5803350915ab4345bac40fb9a0e9
BLAKE2b-256 3eaf9566a139aabb7824583f627a9ba228347ac207e7d092d0010aace4939e5b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for chess_cv-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b25f279796c66c1727e7a49f00237cda1cf4d6e3fd8143f86029c2191f12af89
MD5 9ca58104ad39003e835e43341e808a93
BLAKE2b-256 bc5c16f6a6b84399baca11bf72603cc86070638b0b7f9ffa56bf8b4c799b0793

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