Article Directory
Albumentation
All realized transformations .
Transformation and supported types. Here
Classification
- Create image extension process
Using Compose
the class definition data enhancement process. Compose
The 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),
])
- Read picture
Albumentation
In RGB format
- 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
- 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
,masks
ismask
a list of the composition.
Detection
Four bbox formats:
pascal_voc
:[x_min, y_min, x_max, y_max]
albumentations
:Normalized[x_min, y_min, x_max, y_max]
coco
:[x_min, y_min, width, height]
yolo
:Normalized[x_center, y_center, width, height]
specific process:
- 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.
label_fields
Determine which incoming parameters are used as the category of the bbox.
- 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
- 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)