크롭으로 시작하기 - 크기 정규화가 최우선
기본적인 기하학적 불변성 - 항공 이미지에는 HorizontalFlip, SquareSymmetry
드롭아웃/오클루전 - CoarseDropout, RandomErasing (효과가 큼)
색상 의존도 줄이기 - ToGray, ChannelDropout (필요한 경우)
아핀 변환 - 스케일/회전을 위한 Affine
도메인 특화 - 사용 사례에 맞는 특화된 변환들
정규화 - 표준 또는 샘플별 정규화 (항상 마지막에)
A.Compose([
A.RandomCrop(height=224, width=224), # Step 1: Size
A.HorizontalFlip(p=0.5), # Step 2: Basic geometric
A.CoarseDropout(max_holes=8, max_height=32, max_width=32, p=0.5), # Step 3: Dropout
A.Normalize(), # Step 7: Normalization
])
import albumentations as A
import cv2 # For border_mode constant
TARGET_SIZE = 256
# Example: SmallestMaxSize + RandomCrop (ImageNet style)
train_pipeline_shortest_side = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.RandomCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
# ... other transforms like HorizontalFlip ...
])
val_pipeline_shortest_side = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.CenterCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
# ... other transforms ...
])
# Example: LongestMaxSize + PadIfNeeded (Letterboxing)
pipeline_letterbox = A.Compose([
A.LongestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.PadIfNeeded(min_height=TARGET_SIZE, min_width=TARGET_SIZE,
border_mode=cv2.BORDER_CONSTANT, value=0, p=1.0),
# ... other transforms ...
])
import albumentations as A
TARGET_SIZE = 256
# Example for typical natural images
train_pipeline_step2_natural = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.RandomCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
A.HorizontalFlip(p=0.5),
# ... other transforms ...
])
# Example for aerial/medical images with rotational symmetry
train_pipeline_step2_aerial = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.RandomCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
A.SquareSymmetry(p=0.5), # Applies one of 8 symmetries
# ... other transforms ...
])
import albumentations as A
TARGET_SIZE = 256
# Example adding OneOf dropout transforms
train_pipeline_step3 = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.RandomCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
A.HorizontalFlip(p=0.5),
A.OneOf([
# Use ranges for number/size of holes
A.CoarseDropout(num_holes_range=(1, 8), hole_height_range=(0.1, 0.25),
hole_width_range=(0.1, 0.25), fill_value=0, p=1.0),
# Use ratio and unit size range for grid
A.GridDropout(ratio=0.5, unit_size_range=(0.1, 0.2), p=1.0)
], p=0.5), # Apply one of the dropouts 50% of the time
# ... other transforms ...
])
import albumentations as A
TARGET_SIZE = 256
# Example adding OneOf color dropout transforms
train_pipeline_step4 = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.RandomCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
A.HorizontalFlip(p=0.5),
# Assuming previous dropout step is also included:
A.OneOf([
A.CoarseDropout(num_holes_range=(1, 8), hole_height_range=(0.1, 0.25),
hole_width_range=(0.1, 0.25), fill_value=0, p=1.0),
A.GridDropout(ratio=0.5, unit_size_range=(0.1, 0.2), p=1.0)
], p=0.5),
# Now, apply one of the color-reducing transforms:
A.OneOf([
A.ToGray(p=1.0), # p=1.0 inside OneOf
A.ChannelDropout(p=1.0) # p=1.0 inside OneOf
], p=0.1), # Apply one of these 10% of the time
# ... other transforms ...
])
import albumentations as A
TARGET_SIZE = 256
# Example adding Affine after flips
train_pipeline_step5 = A.Compose([
A.SmallestMaxSize(max_size=TARGET_SIZE, p=1.0),
A.RandomCrop(height=TARGET_SIZE, width=TARGET_SIZE, p=1.0),
A.HorizontalFlip(p=0.5),
A.Affine(
scale=(0.8, 1.2), # Zoom in/out by 80-120%
rotate=(-15, 15), # Rotate by -15 to +15 degrees
# translate_percent=(0, 0.1), # Optional: translate by 0-10%
# shear=(-10, 10), # Optional: shear by -10 to +10 degrees
p=0.7
),
# Step 3: Dropout (example)
A.OneOf([
A.CoarseDropout(num_holes_range=(1, 8), hole_height_range=(0.1, 0.25),
hole_width_range=(0.1, 0.25), fill_value=0, p=1.0),
A.GridDropout(ratio=0.5, unit_size_range=(0.1, 0.2), p=1.0)
], p=0.5),
# Step 4: Color Reduction (example)
A.OneOf([
A.ToGray(p=1.0),
A.ChannelDropout(p=1.0)
], p=0.1),
# ... other transforms ...
])