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 * - 95.78%

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

⚡️ 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.


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.1.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.1-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chess_cv-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7dbbd857f74fd685f1196f052d13f8665bc00d8ff82e280fe86d595ddc13d2cd
MD5 cacbca4121126a0cd1bfa24226ff0270
BLAKE2b-256 831ab777d3dd1f9f18c30c1101e73d3b89e2c64a50d42f0995594692440e44f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chess_cv-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 150b9b1cb1465c1ae8357e1e81d70e52eb7f0f0063e9b1db647f8adc141e1a2d
MD5 7d70610a3b82d8b3d6ddd6a91771a699
BLAKE2b-256 c6169e530e83eb2653bd1ef8927d4b10be781aebbe7c7fab4e36d655b298b9f3

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