augmentation
sleap_nn.data.augmentation
¶
This module implements data pipeline blocks for augmentation operations.
Uses Skia (skia-python) for ~1.5x faster augmentation compared to Kornia.
Functions:
| Name | Description |
|---|---|
apply_flip_augmentation |
Randomly mirror an image and keypoints left/right, swapping symmetric pairs. |
apply_geometric_augmentation |
Apply geometric augmentation on image and instances. |
apply_intensity_augmentation |
Apply intensity augmentation on image and instances. |
apply_flip_augmentation(image, instances, symmetric_inds=None, flip_p=0.0, masks=None)
¶
Randomly mirror an image and keypoints left/right, swapping symmetric pairs.
When an image is mirrored left/right, left/right symmetric body parts physically
exchange sides, so their node slots must be swapped to keep semantic labels
correct. Ported from SLEAP v1.4's RandomFlipper (horizontal flip).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Input image. Shape: (n_samples, C, H, W) |
required |
instances
|
Tensor
|
Input keypoints. (n_samples, n_instances, n_nodes, 2) or (n_samples, n_nodes, 2) |
required |
symmetric_inds
|
Optional[Sequence[Tuple[int, int]]]
|
Iterable of |
None
|
flip_p
|
float
|
Probability of applying the flip. |
0.0
|
masks
|
Optional[Tensor]
|
Optional segmentation masks of shape |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, ...]
|
|
Source code in sleap_nn/data/augmentation.py
apply_geometric_augmentation(image, instances, rotation_min=-15.0, rotation_max=15.0, rotation_p=None, scale_min=0.9, scale_max=1.1, scale_p=None, translate_width=0.02, translate_height=0.02, translate_p=None, affine_p=0.0, erase_scale_min=0.0001, erase_scale_max=0.01, erase_ratio_min=1, erase_ratio_max=1, erase_p=0.0, mixup_lambda_min=0.01, mixup_lambda_max=0.05, mixup_p=0.0, flip_p=0.0, symmetric_inds=None, masks=None)
¶
Apply geometric augmentation on image and instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Input image. Shape: (n_samples, C, H, W) |
required |
instances
|
Tensor
|
Input keypoints. (n_samples, n_instances, n_nodes, 2) or (n_samples, n_nodes, 2) |
required |
rotation_min
|
Optional[float]
|
Minimum rotation angle in degrees. Default: -15.0. |
-15.0
|
rotation_max
|
Optional[float]
|
Maximum rotation angle in degrees. Default: 15.0. |
15.0
|
rotation_p
|
Optional[float]
|
Probability of applying random rotation independently. If None, falls back to affine_p for bundled behavior. Default: None. |
None
|
scale_min
|
Optional[float]
|
Minimum scaling factor for isotropic scaling. Default: 0.9. |
0.9
|
scale_max
|
Optional[float]
|
Maximum scaling factor for isotropic scaling. Default: 1.1. |
1.1
|
scale_p
|
Optional[float]
|
Probability of applying random scaling independently. If None, falls back to affine_p for bundled behavior. Default: None. |
None
|
translate_width
|
Optional[float]
|
Maximum absolute fraction for horizontal translation. Default: 0.02. |
0.02
|
translate_height
|
Optional[float]
|
Maximum absolute fraction for vertical translation. Default: 0.02. |
0.02
|
translate_p
|
Optional[float]
|
Probability of applying random translation independently. If None, falls back to affine_p for bundled behavior. Default: None. |
None
|
affine_p
|
float
|
Probability of applying random affine transformations (rotation, scale, translate bundled). Used when individual *_p params are None. Default: 0.0. |
0.0
|
erase_scale_min
|
Optional[float]
|
Minimum value of range of proportion of erased area against input image. Default: 0.0001. |
0.0001
|
erase_scale_max
|
Optional[float]
|
Maximum value of range of proportion of erased area against input image. Default: 0.01. |
0.01
|
erase_ratio_min
|
Optional[float]
|
Minimum value of range of aspect ratio of erased area. Default: 1. |
1
|
erase_ratio_max
|
Optional[float]
|
Maximum value of range of aspect ratio of erased area. Default: 1. |
1
|
erase_p
|
float
|
Probability of applying random erase. Default: 0.0. |
0.0
|
mixup_lambda_min
|
Optional[float]
|
Minimum mixup strength value. Default: 0.01. |
0.01
|
mixup_lambda_max
|
Optional[float]
|
Maximum mixup strength value. Default: 0.05. |
0.05
|
mixup_p
|
float
|
Probability of applying random mixup v2. Default: 0.0. |
0.0
|
flip_p
|
float
|
Probability of mirroring the sample left/right (with symmetric-node swap). Default: 0.0 (disabled). |
0.0
|
symmetric_inds
|
Optional[Sequence[Tuple[int, int]]]
|
Node-index pairs to swap after mirroring. Passed separately from the config scalars because it is runtime skeleton data. None/empty means no swap. Default: None. |
None
|
masks
|
Optional[Tensor]
|
Optional segmentation masks of shape |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, ...]
|
|
Source code in sleap_nn/data/augmentation.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
apply_intensity_augmentation(image, instances, uniform_noise_min=0.0, uniform_noise_max=0.04, uniform_noise_p=0.0, gaussian_noise_mean=0.0, gaussian_noise_std=0.02, gaussian_noise_p=0.0, contrast_min=0.9, contrast_max=1.1, contrast_p=0.0, brightness_min=0.9, brightness_max=1.1, brightness_p=0.0)
¶
Apply intensity augmentation on image and instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Input image. Shape: (n_samples, C, H, W) |
required |
instances
|
Tensor
|
Input keypoints. (n_samples, n_instances, n_nodes, 2) or (n_samples, n_nodes, 2) |
required |
uniform_noise_min
|
Optional[float]
|
Minimum value for uniform noise (uniform_noise_min >=0). |
0.0
|
uniform_noise_max
|
Optional[float]
|
Maximum value for uniform noise (uniform_noise_max <=1). |
0.04
|
uniform_noise_p
|
float
|
Probability of applying random uniform noise. |
0.0
|
gaussian_noise_mean
|
Optional[float]
|
The mean of the gaussian distribution. |
0.0
|
gaussian_noise_std
|
Optional[float]
|
The standard deviation of the gaussian distribution. |
0.02
|
gaussian_noise_p
|
float
|
Probability of applying random gaussian noise. |
0.0
|
contrast_min
|
Optional[float]
|
Minimum contrast factor to apply. Default: 0.5. |
0.9
|
contrast_max
|
Optional[float]
|
Maximum contrast factor to apply. Default: 2.0. |
1.1
|
contrast_p
|
float
|
Probability of applying random contrast. |
0.0
|
brightness_min
|
Optional[float]
|
Minimum brightness factor to apply. Default: 1.0. |
0.9
|
brightness_max
|
Optional[float]
|
Maximum brightness factor to apply. Default: 1.0. |
1.1
|
brightness_p
|
float
|
Probability of applying random brightness. |
0.0
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Returns tuple: (image, instances) with augmentation applied. |