File size: 2,558 Bytes
a81eaa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
116
117
118
---
license: apache-2.0
tags:
- computer-vision
- chess
- yolo
- segmentation
- instance-segmentation

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

# chess_board_segmentation

ChessBoard segmentation model trained with YOLO

## Model Details

- **Model Type**: YOLO Segmentation
- **Task**: instance-segmentation
- **License**: apache-2.0

## Usage

### Loading the Model

```python
from src.chess_board_detection.yolo.segmentation.segmentation_model import ChessBoardSegmentationModel

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

# Get polygon coordinates for a chessboard
polygon_info, is_valid = model.get_polygon_coordinates("path/to/chessboard_image.jpg")

if is_valid:
    print(f"Detected chessboard polygon: {polygon_info}")
    
    # Extract corners from the segmentation
    corners = model.extract_corners_from_segmentation(
        "path/to/chessboard_image.jpg", 
        polygon_info
    )
    print(f"Extracted corners: {corners}")

# Visualize results
model.plot_eval("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 segmentation
results = model("path/to/chessboard_image.jpg")

# Get masks and polygons
for result in results:
    if result.masks is not None:
        for mask in result.masks:
            polygon = mask.xy[0]  # Polygon coordinates
            print(f"Polygon points: {polygon}")
```

### Training Data Format

This model expects YOLO segmentation format with polygon annotations:

```yaml
# data.yaml
train: path/to/train/images
val: path/to/val/images
nc: 1
names: ['chessboard']
```

With corresponding label files containing polygon coordinates:
```
# labels/image.txt
0 x1 y1 x2 y2 x3 y3 x4 y4 ...  # normalized coordinates
```

## Training

This model was trained using the ChessBoard Segmentation training pipeline:

```bash
python src/chess_board_detection/yolo/segmentation/train_segmentation.py \
    --data data/chessboard_segmentation/chess-board-3/data.yaml \
    --epochs 100 \
    --batch 16 \
    --pretrained-model yolov8s-seg.pt
```

## Model Performance

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

## Citation

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

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