File size: 2,565 Bytes
115dd41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
license: apache-2.0
tags:
- computer-vision
- chess
- yolo
- object-detection
- piece-detection

model-index:
- name: chess_piece_detection
  results: []
---

# chess_piece_detection

Chess piece detection model trained with YOLO

## Model Details

- **Model Type**: YOLO Detection
- **Task**: object-detection
- **License**: apache-2.0

## Usage

### Loading the Model

```python
from src.chess_piece_detection.model import ChessModel

# Load the model
model = ChessModel(model_path="path/to/downloaded/model.pt")

# Detect chess pieces in an image
detected_pieces = model.detect_pieces("path/to/chessboard_image.jpg")

for square_num, piece_class in detected_pieces:
    piece_name = model.get_piece_name(piece_class)
    print(f"Square {square_num}: {piece_name}")

# Visualize results
model.visualize_detections("path/to/chessboard_image.jpg", show=True)
```

### Direct YOLO Usage

```python
from ultralytics import YOLO

# Load the model
model = YOLO("path/to/downloaded/model.pt")

# Run detection on chess piece images
results = model("path/to/chessboard_image.jpg")

# Get bounding boxes and classifications
for result in results:
    boxes = result.boxes
    if boxes is not None:
        for box in boxes:
            class_id = int(box.cls[0])
            confidence = float(box.conf[0])
            print(f"Detected piece class {class_id} with confidence {confidence:.2f}")
```

### Training Data Format

This model expects YOLO detection format with chess piece annotations:

```yaml
# data.yaml
train: path/to/train/images
val: path/to/val/images
nc: 12  # Number of chess piece classes
names: ['white-king', 'white-queen', 'white-rook', 'white-bishop', 'white-knight', 'white-pawn', 
        'black-king', 'black-queen', 'black-rook', 'black-bishop', 'black-knight', 'black-pawn']
```

With corresponding label files containing piece bounding boxes:
```
# labels/image.txt
class_id x_center y_center width height  # normalized coordinates
```

## Training

This model was trained using the Chess Piece Detection training pipeline:

```bash
python src/chess_piece_detection/train.py \
    --data data/chess_pieces/data.yaml \
    --epochs 100 \
    --batch 16 \
    --img-size 640
```

## Model Performance

<!-- Add performance metrics here after training -->

## Citation

If you use this model in your research, please cite:

```bibtex
@misc{dopaul_chess_piece_detection,
    title={chess_piece_detection},
    author={dopaul},
    year={2024},
    publisher={Hugging Face},
    url={https://huggingface.co/dopaul/chess_piece_detection}
}
```