Albumentation

Albumentation

All realized transformations .

Transformation and supported types. Here

Classification

  1. Create image extension process

Using Composethe class definition data enhancement process. ComposeThe class accepts a list of all image transformations.

transform = A.Compose([
    A.RandomCrop(width=256, height=256),
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(p=0.2),
])
  1. Read picture
  • Albumentation In RGB format
  1. Pass in the picture, get the transformed picture
# 返回是字典
transformed_image = transform(image=image)["image"]

Segmentation

Need to change the picture and Mask at the same time. 1, 2 The two cloths are the same as Classification, the third step

  1. Incoming picture and mask
transformed = transform(image=image, mask=mask)
transformed_image = transformed['image']
transformed_mask = transformed['mask']

If you pass multiple Mask, adopt transform(image=image, masks=masks, masksis maska list of the composition.

Detection

Four bbox formats:

  1. pascal_voc[x_min, y_min, x_max, y_max]
  2. albumentationsNormalized [x_min, y_min, x_max, y_max]
  3. coco[x_min, y_min, width, height]
  4. yoloNormalized [x_center, y_center, width, height]

specific process:

  1. Augmentaion Pipeline
transform = A.Compose([
    A.RandomCrop(width=450, height=450),
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(p=0.2),
], bbox_params=A.BboxParams(format='coco', min_area=1024, min_visibility=0.1, label_fields=['class_labels']))

min_area is a value in pixels. If the area of a bounding box after augmentation becomes smaller than min_area, Albumentations will drop that box.

min_visibility is a value between 0 and 1. If the ratio of the bounding box area after augmentation to the area of the bounding box before augmentation becomes smaller than min_visibility, Albumentations will drop that box.

Insert picture description here
label_fields Determine which incoming parameters are used as the category of the bbox.

  1. Pass Image and labels

In the following example, each bbox has two classes ( class_labels, class_categories).

transform = A.Compose([
    A.RandomCrop(width=450, height=450),
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(p=0.2),
], bbox_params=A.BboxParams(format='coco', label_fields=['class_labels', 'class_categories'])))

class_labels = ['cat', 'dog', 'parrot']
class_categories = ['animal', 'animal', 'item']

transformed = transform(image=image, bboxes=bboxes, class_labels=class_labels, class_categories=class_categories) # 传入参数由 `Compose` 中 `label_fields` 决定
transformed_image = transformed['image']
transformed_bboxes = transformed['bboxes']
transformed_class_labels = transformed['class_labels']
transformed_class_categories = transformed['class_categories']

KeyPoints Augmentation

Supported keypoint format, here

  1. Augmentation Pipeline
transform = A.Compose([
    A.RandomCrop(width=330, height=330),
    A.RandomBrightnessContrast(p=0.2),
], keypoint_params=A.KeypointParams(format='xy', label_fields=['class_labels'], remove_invisible=True, angle_in_degrees=True))

label_fields:In some computer vision tasks, keypoints have not only coordinates but associated labels as well. (different kinds of keypoints)

Guess you like

Origin blog.csdn.net/lib0000/article/details/113983564