62 lines
2.0 KiB
Markdown
62 lines
2.0 KiB
Markdown
# YOLOv9 dataset augmentation
|
||
|
||
Augment a YOLOv9-format dataset by creating new image and label files for horizontal flip, vertical flip, +10% hue, +30% contrast, and grayscale. Labels are updated correctly for flips; other augmentations copy labels unchanged.
|
||
|
||
## Dataset layout
|
||
|
||
Expected structure:
|
||
|
||
```
|
||
dataset/
|
||
├── images/ # .jpg or .png
|
||
│ ├── img1.jpg
|
||
│ └── img2.jpg
|
||
└── labels/ # .txt, one per image, same base name
|
||
├── img1.txt
|
||
└── img2.txt
|
||
```
|
||
|
||
YOLO label format: one line per object: `class_id x_center y_center width height` (normalized 0–1).
|
||
|
||
If `images/` and `labels/` are not present, the script treats the given directory as containing both images and labels (flat layout).
|
||
|
||
## Setup
|
||
|
||
```bash
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
## Usage
|
||
|
||
Augment in place (new files appear next to originals in `images/` and `labels/`):
|
||
|
||
```bash
|
||
python augment_yolov9_dataset.py --dataset-dir ./dataset/train
|
||
```
|
||
|
||
Write augmented files to a separate directory (creates `train_aug/images/` and `train_aug/labels/`):
|
||
|
||
```bash
|
||
python augment_yolov9_dataset.py --dataset-dir ./dataset/train --output-dir ./dataset/train_aug
|
||
```
|
||
|
||
Other options:
|
||
|
||
- `--image-ext .png` — look for `.png` instead of `.jpg`
|
||
- `--suffixes hflip vflip` — run only horizontal and vertical flip (choices: `hflip`, `vflip`, `hue`, `contrast`, `gray`)
|
||
- `--dry-run` — print which files would be created without writing
|
||
|
||
## Output naming
|
||
|
||
For each image `img.jpg` with label `img.txt`, the script can create:
|
||
|
||
| Augmentation | Image | Label |
|
||
|----------------|-----------------|-----------------|
|
||
| Horizontal flip| `img_hflip.jpg` | `img_hflip.txt` |
|
||
| Vertical flip | `img_vflip.jpg` | `img_vflip.txt` |
|
||
| Hue +10% | `img_hue.jpg` | `img_hue.txt` |
|
||
| Contrast +30% | `img_contrast.jpg` | `img_contrast.txt` |
|
||
| Grayscale | `img_gray.jpg` | `img_gray.txt` |
|
||
|
||
Add these paths to your YOLOv9 data YAML or file lists to use the augmented set.
|