Skip to content

ramosleandre/my_torch

Repository files navigation

G-CNA - Chess Position Classifier

Neural network library from scratch applied to chess position classification.

Results

Model Params Best Accuracy Time
Small 213,637 89.97% 392s
Medium 467,973 90.78% 781s
Large 566,533 92.08% 2366s

Dataset: 2.3M training (x4 augmented) / 550K test (x4 augmented)

Training Metrics

Quick Start

# 1. Prepare dataset
python scripts/dataset/prepare.py

# 2. Augment (x4 with flip + color inversion)
python scripts/dataset/augment.py --mode both

# 3. Train
python scripts/training/train.py --arch large --epochs 20 --save model_large.nn

# 4. Demo
python demo/server.py  # Open http://localhost:8080

5-Class Classification

Class Description
0 Nothing (normal position)
1 Check White
2 Check Black
3 Checkmate White
4 Checkmate Black

The Library: my_torch

PyTorch-like API built from scratch with NumPy:

from my_torch.nn import Linear, ReLU, Dropout, Softmax, CrossEntropyLoss
from my_torch.optim import Adam, ReduceLROnPlateau

Features:

  • Tensor with gradient tracking
  • Layers: Linear, Dropout, BatchNorm1d
  • Activations: ReLU, LeakyReLU, Sigmoid, Softmax
  • Loss: MSELoss, CrossEntropyLoss
  • Optimizers: SGD (momentum), Adam
  • LR Schedulers: StepLR, ExponentialLR, ReduceLROnPlateau
  • Gradient Clipping: clip_grad_norm, clip_grad_value

See my_torch/README.md for full API.

Data Augmentation

python scripts/dataset/augment.py --mode both  # x4
Mode Effect Multiplier
flip Horizontal mirror x2
invert 180° rotation + color swap + label swap x2
both All combinations x4

Model Architectures

Model Architecture Params
FenSmall 768→256→64→5 214k
FenMedium 768→512→128→64→5 468k
FenLarge 768→512→256→128→64→5 567k

Testing

pytest test/ -v                     # 140+ tests
pytest test/test_conformity.py -v   # PyTorch comparison (10 tests)

PyTorch Conformity Tests:

  • Linear forward
  • ReLU, Sigmoid, Softmax
  • MSELoss, CrossEntropyLoss
  • BatchNorm1d
  • SGD, Adam optimizers

Project Structure

├── my_torch/          # Neural network library
├── scripts/
│   ├── dataset/       # prepare.py, augment.py
│   ├── training/      # train.py, search.py
│   └── benchmark/     # compare.py, visualize.py
├── demo/              # Web interface
├── test/              # 140+ unit tests
└── dataset/           # FEN data

Epitech Project G-CNA-500

About

An implementation of torch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors