Reference for ultralytics/data/augment.py
Note
Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/data/augment.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!
ultralytics.data.augment.BaseTransform
Source code in ultralytics/data/augment.py
__call__(labels)
Applies label transformations to an image, instances and semantic masks.
apply_image(labels)
apply_instances(labels)
ultralytics.data.augment.Compose
Source code in ultralytics/data/augment.py
__call__(data)
__init__(transforms)
__repr__()
append(transform)
ultralytics.data.augment.BaseMixTransform
This implementation is from mmyolo.
Source code in ultralytics/data/augment.py
__call__(labels)
Applies pre-processing transforms and mixup/mosaic transforms to labels data.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.Mosaic
Bases: BaseMixTransform
Mosaic augmentation.
This class performs mosaic augmentation by combining multiple (4 or 9) images into a single mosaic image. The augmentation is applied to a dataset with a given probability.
Attributes:
Name | Type | Description |
---|---|---|
dataset |
The dataset on which the mosaic augmentation is applied. |
|
imgsz |
int
|
Image size (height and width) after mosaic pipeline of a single image. Default to 640. |
p |
float
|
Probability of applying the mosaic augmentation. Must be in the range 0-1. Default to 1.0. |
n |
int
|
The grid size, either 4 (for 2x2) or 9 (for 3x3). |
Source code in ultralytics/data/augment.py
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
__init__(dataset, imgsz=640, p=1.0, n=4)
Initializes the object with a dataset, image size, probability, and border.
Source code in ultralytics/data/augment.py
get_indexes(buffer=True)
Return a list of random indexes from the dataset.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.MixUp
Bases: BaseMixTransform
Source code in ultralytics/data/augment.py
ultralytics.data.augment.RandomPerspective
Source code in ultralytics/data/augment.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
__call__(labels)
Affine images and targets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels |
dict
|
a dict of |
required |
Source code in ultralytics/data/augment.py
affine_transform(img, border)
Center.
Source code in ultralytics/data/augment.py
apply_bboxes(bboxes, M)
Apply affine to bboxes only.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bboxes |
ndarray
|
list of bboxes, xyxy format, with shape (num_bboxes, 4). |
required |
M |
ndarray
|
affine matrix. |
required |
Returns:
Name | Type | Description |
---|---|---|
new_bboxes |
ndarray
|
bboxes after affine, [num_bboxes, 4]. |
Source code in ultralytics/data/augment.py
apply_keypoints(keypoints, M)
Apply affine to keypoints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keypoints |
ndarray
|
keypoints, [N, 17, 3]. |
required |
M |
ndarray
|
affine matrix. |
required |
Returns:
Name | Type | Description |
---|---|---|
new_keypoints |
ndarray
|
keypoints after affine, [N, 17, 3]. |
Source code in ultralytics/data/augment.py
apply_segments(segments, M)
Apply affine to segments and generate new bboxes from segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segments |
ndarray
|
list of segments, [num_samples, 500, 2]. |
required |
M |
ndarray
|
affine matrix. |
required |
Returns:
Name | Type | Description |
---|---|---|
new_segments |
ndarray
|
list of segments after affine, [num_samples, 500, 2]. |
new_bboxes |
ndarray
|
bboxes after affine, [N, 4]. |
Source code in ultralytics/data/augment.py
ultralytics.data.augment.RandomHSV
Source code in ultralytics/data/augment.py
__call__(labels)
Applies image HSV augmentation
Source code in ultralytics/data/augment.py
ultralytics.data.augment.RandomFlip
Applies random horizontal or vertical flip to an image with a given probability.
Source code in ultralytics/data/augment.py
__call__(labels)
Resize image and padding for detection, instance segmentation, pose.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.LetterBox
Resize image and padding for detection, instance segmentation, pose.
Source code in ultralytics/data/augment.py
__call__(labels=None, image=None)
Return updated labels and image with added border.
Source code in ultralytics/data/augment.py
__init__(new_shape=(640, 640), auto=False, scaleFill=False, scaleup=True, center=True, stride=32)
Initialize LetterBox object with specific parameters.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.CopyPaste
Source code in ultralytics/data/augment.py
__call__(labels)
Implement Copy-Paste augmentation https://arxiv.org/abs/2012.07177, labels as nx5 np.array(cls, xyxy).
Source code in ultralytics/data/augment.py
ultralytics.data.augment.Albumentations
Albumentations transformations. Optional, uninstall package to disable. Applies Blur, Median Blur, convert to grayscale, Contrast Limited Adaptive Histogram Equalization, random change of brightness and contrast, RandomGamma and lowering of image quality by compression.
Source code in ultralytics/data/augment.py
__call__(labels)
Generates object detections and returns a dictionary with detection results.
Source code in ultralytics/data/augment.py
__init__(p=1.0)
Initialize the transform object for YOLO bbox formatted params.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.Format
Source code in ultralytics/data/augment.py
__call__(labels)
Return formatted image, classes, bounding boxes & keypoints to be used by 'collate_fn'.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.ClassifyLetterBox
YOLOv8 LetterBox class for image preprocessing, i.e. T.Compose([LetterBox(size), ToTensor()])
Source code in ultralytics/data/augment.py
__init__(size=(640, 640), auto=False, stride=32)
Resizes image and crops it to center with max dimensions 'h' and 'w'.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.CenterCrop
YOLOv8 CenterCrop class for image preprocessing, i.e. T.Compose([CenterCrop(size), ToTensor()])
Source code in ultralytics/data/augment.py
__init__(size=640)
ultralytics.data.augment.ToTensor
YOLOv8 ToTensor class for image preprocessing, i.e. T.Compose([LetterBox(size), ToTensor()]).
Source code in ultralytics/data/augment.py
ultralytics.data.augment.v8_transforms(dataset, imgsz, hyp, stretch=False)
Convert images to a size suitable for YOLOv8 training.
Source code in ultralytics/data/augment.py
ultralytics.data.augment.classify_transforms(size=224, mean=(0.0, 0.0, 0.0), std=(1.0, 1.0, 1.0))
Source code in ultralytics/data/augment.py
ultralytics.data.augment.hsv2colorjitter(h, s, v)
Map HSV (hue, saturation, value) jitter into ColorJitter values (brightness, contrast, saturation, hue)
ultralytics.data.augment.classify_albumentations(augment=True, size=224, scale=(0.08, 1.0), hflip=0.5, vflip=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, mean=(0.0, 0.0, 0.0), std=(1.0, 1.0, 1.0), auto_aug=False)
YOLOv8 classification Albumentations (optional, only used if package is installed).