- Chessboard corners and chess pieces detected with YOLOv8. The position of the chess pieces on the board was converted to digital notation and best move analysis was done with Stockfish. The interface has been designed and usage simplified.
Object detection with YOLOv8, best move prediction with Stockfish
Datasets are trained with 16GB Tesla T4 GPU via Google Colab.
- If you want to make a new train, first run the Roboflow code that contains the API code.
pip install roboflow
from roboflow import Roboflow
rf = Roboflow(api_key="*******************")
project = rf.workspace("***********").project("corner-2")
dataset = project.version(3).download("yolov8")
Chess board corners dataset: https://universe.roboflow.com/nstuchess-iz6hx/corners-hzmj3/dataset/1
Perspective transformed chess pieces dataset: https://universe.roboflow.com/nstuchess-iz6hx/chess-detection-3/dataset/1
Chess board corners detection training results (100 epoch)
Perspective transformed chess pieces training results (75 epoch)
- A virtual environment is created for the system. (Assuming you have Anaconda installed.)
conda create -n chess_vision python -y
conda activate chess_vision
- Clone repo and install requirements.txt in a Python>=3.7.0 (3.9 recommended) environment, including PyTorch>=1.7 (1.9.0 recommended).
git clone https://github.com/zahidesatmutlu/Chess-Vision-and-Stockfish-Prediction # clone
pip install ultralytics # install
- Install CUDA Toolkit version 11.6 and install PyTorch version 1.9.0.
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
- The file structure should be like this:
chess_vision/
.idea
__pycache__
runs
venv
best_corners.pt
best_transformed_detection.pt
chessboard_detection.py
chessboard_transformed_with_grid.jpg
download_dataset.py
main.py
stockfish_interface.py
stockfish_interface.ui
If you use this package in your work, please cite it as:
James Gallagher. (Mar 10, 2023). Represent Chess Boards Digitally with Computer Vision. Roboflow Blog: /chess-boards/