🧠 Chessboard Recognizer (Convert your chess images to FEN positions with one click!)
This project uses a deep learning model implemented in PyTorch to recognize the positions of chess pieces on a chessboard image and convert it into FEN notation. This library introduces an easy and fast function to simply predict a fen from an image, it vastly increases prediction accuracy, encompassing a wide variety of chess image formats from different sources. For more advanced usage it also provides reusable components for training, inference, and data preparation.
Full credits to linrock/chessboard-recognizer for chess image data, preprocessing and basis for the training algorithm, originally a simple CNN architecture built on a no longer supported version of TensorFlow 2. This version transitions to PyTorch and vastly improves prediction accuracy on a wide variety of chess image formats.
🧪 Usage Example
Check the demo usage notebook
for more advanced usages (training/inference)
📓 examples/demo_usage.ipynb
Predict from an image
from chessimg2pos import predict_fen
fen = predict_fen("../images/chess_image.png")
print(fen)
Output:
11111111/11111111/11111111/1111p1K1/11k1P111/11111111/11111111/11111111
🖼️ Sample Results
---🚀 Getting Started
Requirements
- Python 3.10–3.14
- PyTorch
- Other dependencies in
requirements.txt
pip install chessimg2pos
or
git clone https://github.com/mdicio/chessimg2pos
pip install -r requirements.txt
🙏 Acknowledgements
This project is a continuation and modernization of:
- linrock/chessboard-recognizer — the original TensorFlow implementation
- tensorflow_chessbot by Elucidation
Major thanks to these creators — this project wouldn’t exist without their work.
🧠 Core Classes
This project is centered around two powerful classes that handle training and prediction with a modern PyTorch-based architecture.
🔧 ChessRecognitionTrainer
Handles training and evaluation of the CNN-based chess piece classifier.
Example:
from chessimg2pos import ChessRecognitionTrainer
trainer = ChessRecognitionTrainer(
images_dir="../../training_images/chessboards", # replace with your path
model_path="../../models/test_model.pt",# replace with path where you want models tgo be saved
generate_tiles=False, # Set to True if tiles need to be generated from boards
epochs = 5,
overwrite = False
)
model, device, accuracy = trainer.train(classifier="enhanced")
🔍 ChessPositionPredictor
Loads a trained model and predicts a FEN string from a chessboard image.
Example:
from chessimg2pos import ChessPositionPredictor
predictor = ChessPositionPredictor("../../models/test_model.pt")
result = predictor.predict_chessboard("../images/ccom_1.png", return_tiles=True)
print("Predicted FEN:", result["fen"])
print("Confidence:", result["confidence"])
predictor.visualize_prediction(result)
Metadata
Release files for chessimg2pos 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chessimg2pos-0.1.6.tar.gz | 318.9 kB | Without provenance | Details for chessimg2pos-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chessimg2pos-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for chessimg2pos-0.1.6-py3-none-any.whl |
Total release size: 344.2 kB
Release files / chessimg2pos-0.1.6.tar.gz
| Download URL | chessimg2pos-0.1.6.tar.gz |
|---|---|
| Size | 318.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20fad210354b67e64d69b1b1680b0798cbdbd2335a73751788d10e49bf182d8b
|
|
BLAKE2b-256 checksum How to use checksums |
23699bf599bf193dad2e99e77265cf15ce70e4ae42fd72f0a9efd74cf4bc16ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Release files / chessimg2pos-0.1.6-py3-none-any.whl
| Download URL | chessimg2pos-0.1.6-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
016b7e17063206f8f917191c504b1a188ad5500e361a20382ce6c7b8f6bdd65b
|
|
BLAKE2b-256 checksum How to use checksums |
10510d48714ef4aab8559e3a9ec8c58eeb3b6453116d8126b9af259c27c01a68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Security for chessimg2pos 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.