2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
1. Data Augmentation
1. Augment an existing dataset to make it more diverse, such as adding different background noises, changing the color and shape of the image.
2. Augmented data is generated online
3. Enhancement type:
(1) Flip
(2) Cutting
(3) Color
(4) Sharpening and adding spots
2. Conclusion
1. Data augmentation obtains diversity by deforming data, thereby making the model more generalizable.
2. Common image augmentations include flipping, cutting, and color change
3. Just change the data set
4. In order to obtain accurate results during the prediction process, we usually only perform image augmentation on the training samples, and do not use image augmentation with random operations during the prediction process.
5. Deep learning frameworks provide many different image augmentation methods that can be applied simultaneously.
3. Code
1. Augmentation methodaug
def apply(img, aug, num_rows=2, num_cols=4, scale=1.5): Y = [aug(img) for _ in range(num_rows * num_cols)] d2l.show_images(Y, num_rows, num_cols, scale=scale)
2. Flip
apply(img, torchvision.transforms.RandomHorizontalFlip()) apply(img, torchvision.transforms.RandomVerticalFlip())
3. Cropping
#面积为原始面积10%到100%的区域,宽高比从0.5~2之间随机取值 shape_aug = torchvision.transforms.RandomResizedCrop( (200, 200), scale=(0.1, 1), ratio=(0.5, 2)) apply(img, shape_aug)
4. Brightness
apply(img, torchvision.transforms.ColorJitter( brightness=0.5, contrast=0, saturation=0, hue=0))
5. Hue
apply(img, torchvision.transforms.ColorJitter( brightness=0, contrast=0, saturation=0, hue=0.5))
brightness(brightness
)、Contrast(contrast
),saturation(saturation
) and hue (hue
)
6. Mix
augs = torchvision.transforms.Compose([ torchvision.transforms.RandomHorizontalFlip(), color_aug, shape_aug]) apply(img, augs)