ChessCV Lichess FEN Square Classifier

This repository contains an MLX chess-board square classifier for FEN recognition from Lichess-style 2D board screenshots.

The model classifies each 64ร—64 RGB/BGR-normalized board-square crop into one of 13 classes: empty square plus the 12 standard chess pieces. A full FEN can be produced by running the classifier over all 64 square crops in board order and converting the predicted class sequence into piece-placement notation.

Model file

  • mlx_model_lichess_fen_64.safetensors โ€” MLX weights for ChessPieceCNN64
  • mlx_model.py โ€” MLX model definitions
  • labels.json โ€” class-index mapping
  • training_config.json โ€” high-level training metadata

Labels

0: empty
1: white pawn
2: white rook
3: white knight
4: white bishop
5: white queen
6: white king
7: black pawn
8: black rook
9: black knight
10: black bishop
11: black queen
12: black king

Input format

  • Shape: (N, 64, 64, 3)
  • Value range: float32 normalized to [0, 1]
  • Channel order: use the same channel order as your OpenCV crop pipeline. This model was trained from OpenCV-rendered crops.

For board-level FEN recognition, crop the detected board into 64 squares, resize each crop to 64ร—64, run batch inference, then map argmax outputs to FEN piece-placement symbols. For black-side board orientation, reverse the 64 square predictions before converting to canonical FEN.

Example usage

import mlx.core as mx
import numpy as np
from mlx_model import ChessPieceCNN64

model = ChessPieceCNN64()
model.load_weights("mlx_model_lichess_fen_64.safetensors")

# batch: np.ndarray shaped (64, 64, 64, 3), float32 in [0, 1]
logits = model(mx.array(batch))
mx.eval(logits)
labels = np.argmax(np.array(logits), axis=1)

Training and verification summary

The model was trained on synthetic square crops generated from Lichess default cburnett piece assets, with Lichess-like board colors, empty squares, scale changes, compression artifacts, blur, lighting/gamma variation, and small-screen resampling effects.

Final training run:

  • Input size: 64ร—64
  • Samples: 240,000
  • Epochs: 14
  • Empty-square samples: ~38%
  • Final training accuracy: 99.98%

Rendered Lichess-board verification:

  • Boards are rendered from Lichess default pieces
  • Boards are split into 64 independent square crops
  • Both normal and black-side-flipped orientations are tested
  • Verification result: 15,872 / 15,872 squares correct across 248 board trials

Intended use

This model is intended as a component in chess computer-vision pipelines that detect a 2D chessboard on screen and reconstruct the piece-placement part of a FEN string.

License and source assets

The model was trained using Lichess piece assets from the open-source Lichess project. Lichess is distributed under AGPL-3.0-or-later; individual piece sets may have their own original author/license history upstream.

Downloads last month

-

Downloads are not tracked for this model. How to track
MLX
Hardware compatibility
Log In to add your hardware

Quantized

Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support