Data API¶
Datasets¶
modern_yolonas.data.coco.COCODetectionDataset
¶
Bases: Dataset
COCO-format detection dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str | Path
|
Path to image directory (e.g., |
required |
ann_file
|
str | Path
|
Path to annotation JSON (e.g., |
required |
transforms
|
Transform | None
|
|
None
|
input_size
|
int
|
Target input size (used by transforms). |
640
|
Source code in src/modern_yolonas/data/coco.py
load_raw(index)
¶
Load image and targets without transforms.
Source code in src/modern_yolonas/data/coco.py
modern_yolonas.data.yolo.YOLODetectionDataset
¶
Bases: Dataset
Source code in src/modern_yolonas/data/yolo.py
Transforms¶
modern_yolonas.data.transforms
¶
Detection-aware data augmentations.
Each transform operates on (image, targets) where:
- image: HWC uint8 BGR numpy array
- targets: [N, 5] numpy array with [class_id, x_center, y_center, w, h] (normalized)
HSVAugment, HorizontalFlip, RandomAffine, RandomResizedCrop, and
RandomChannelSwap are backed by Albumentations <https://albumentations.ai>_
(MIT license, v2+).
Mosaic, Mixup, LetterboxResize, and Normalize use native implementations
because they have no direct Albumentations equivalent.
Compose
¶
Chain multiple transforms sequentially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
list
|
List of callables, each accepting |
required |
Source code in src/modern_yolonas/data/transforms.py
HSVAugment
¶
Randomly adjust hue, saturation, and value via Albumentations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hgain
|
int
|
Max hue shift in degrees (Albumentations |
18
|
sgain
|
int
|
Max saturation shift in absolute units ( |
30
|
vgain
|
int
|
Max value shift in absolute units ( |
30
|
p
|
float
|
Probability of applying the transform. |
0.5
|
Source code in src/modern_yolonas/data/transforms.py
HorizontalFlip
¶
Randomly flip the image and bounding boxes horizontally via Albumentations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of applying the flip. |
0.5
|
Source code in src/modern_yolonas/data/transforms.py
RandomAffine
¶
Apply random rotation, scale, translation, and shear via Albumentations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
float
|
Maximum rotation in degrees. |
0.0
|
translate
|
float
|
Maximum translation as a fraction of image size. |
0.25
|
scale
|
tuple[float, float]
|
Scale range |
(0.5, 1.5)
|
shear
|
float
|
Maximum shear in degrees. |
0.0
|
Source code in src/modern_yolonas/data/transforms.py
RandomResizedCrop
¶
Randomly crop a region of the image and resize it to size via Albumentations.
Mirrors torchvision.transforms.RandomResizedCrop but is bounding-box
aware. Boxes whose area falls below min_width / min_height pixels
after cropping are automatically discarded by _BBOX_PARAMS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Output square side length in pixels. |
640
|
scale
|
tuple[float, float]
|
Range of fraction of the original image area to crop.
Default |
(0.08, 1.0)
|
ratio
|
tuple[float, float]
|
Range of aspect ratio of the crop.
Default |
(0.75, 1.333)
|
interpolation
|
int
|
OpenCV interpolation flag (default |
INTER_LINEAR
|
p
|
float
|
Probability of applying the transform. |
1.0
|
Source code in src/modern_yolonas/data/transforms.py
RandomChannelSwap
¶
Randomly swap BGR channel order to RGB (and vice-versa) via Albumentations.
Adds photometric variety without touching bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of swapping channels. |
0.5
|
Source code in src/modern_yolonas/data/transforms.py
CenterCrop
¶
Crop the center of the image to size × size pixels.
Bounding boxes that fall outside the cropped region are discarded;
those that overlap are clipped to the new canvas by _BBOX_PARAMS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Output square side length in pixels. |
640
|
Source code in src/modern_yolonas/data/transforms.py
Mosaic
¶
4-image mosaic augmentation.
Source code in src/modern_yolonas/data/transforms.py
Mixup
¶
Mixup augmentation for detection.
Should be placed in the pipeline after LetterboxResize and
before Normalize, so both images are already square uint8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
BaseDetectionDataset
|
Dataset exposing a |
required |
p
|
float
|
Per-sample probability of applying mixup. |
0.5
|
alpha
|
float
|
Beta distribution |
1.5
|
beta
|
float
|
Beta distribution |
1.5
|
Source code in src/modern_yolonas/data/transforms.py
LetterboxResize
¶
Resize with aspect ratio preservation and center padding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_size
|
int
|
Output square dimension. |
640
|
pad_value
|
int
|
Pixel value for padding (default 114, matching YOLO convention). |
114
|
Source code in src/modern_yolonas/data/transforms.py
Normalize
¶
Convert HWC uint8 to CHW float32 [0,1] tensor.