2026-02-04 15:29:36 +07:00
2026-02-04 15:29:36 +07:00
2026-02-04 15:22:28 +07:00
2026-02-04 15:22:28 +07:00
2026-02-04 15:22:28 +07:00

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 01).

If images/ and labels/ are not present, the script treats the given directory as containing both images and labels (flat layout).

Setup

pip install -r requirements.txt

Usage

Augment in place (new files appear next to originals in images/ and labels/):

python augment_yolov9_dataset.py --dataset-dir ./dataset/train

Write augmented files to a separate directory (creates train_aug/images/ and train_aug/labels/):

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.

Description
script python untuk proses dataset
Readme 260 MiB
Languages
TypeScript 48.7%
Python 47.9%
Jupyter Notebook 1.4%
CSS 0.7%
Shell 0.5%
Other 0.7%