C.W.K.
Stream
Lesson 05 of 06 · published

Augmentation layer

~8 min · keras-cv

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

Augmentation 은 공짜 regularization

vision model 을 일반화시키는 제일 싼 방법은 더 많은 다양성을 보여주는 거 — 더 많은 *이미지* 가 아니라, 가진 이미지의 더 많은 *버전*. flip, rotate, crop, recolor: transform 하나하나가 model 한테 '고양이는 거꾸로여도, 그늘 속이어도 고양이' 라고 가르쳐. KerasCV layer 는 이걸 input pipeline 의 일부로 GPU 에서 on-the-fly 처리 — 비용 거의 0, 원본 dataset 은 disk 에서 안 커져.

KerasCV 가 기본 flip/rotation 을 앞서는 지점은 두 sample 을 섞는 *batch-level* augmentation 이야:

Augmentation설명
CutMix한 이미지에서 random patch 잘라 다른 이미지에 붙이고, label 을 비율대로 섞음
MixUp두 이미지 + label 사이 linear interpolation
RandAugment미리 정의된 집합에서 N 개 transform 의 random policy 적용 — 수동 튜닝 불필요
MosaicAugmentation이미지 4 장을 mosaic 로 결합 (YOLO 학습에 사용)

label 섞기가 왜 먹히냐

MixUp / CutMix 는 처음엔 틀려 보이는 짓을 해 — *반쯤* 고양이고 *반쯤* 개인 이미지를, 거기 맞는 label (0.7 고양이, 0.3 개) 이랑 같이 만들어. 이게 model 의 overconfidence 를 깨버려 — 날카로운 경계를 외우는 대신 부드러운 decision boundary 를 배우고, 그게 정확히 overfitting 을 줄이는 거야. SOTA classification 레시피의 표준인 이유. 단서: *학습* 때만 적용되고, vanilla augmentation 보다 hyperparameter 에 민감해.

Code

batch-mixing + policy 기반 augmenter·python
# CutMix and MixUp
augmenter = keras_cv.layers.CutMix(alpha=1.0)
augmenter = keras_cv.layers.MixUp(alpha=0.2)

# RandAugment
augmenter = keras_cv.layers.RandAugment(
    value_range=(0, 255), augmentations_per_image=3
)
tf.data input pipeline 에 augmentation 연결·python
# Apply during training only, on the input pipeline
train_ds = train_ds.map(
    lambda x, y: augmenter({"images": x, "labels": y}),
    num_parallel_calls=tf.data.AUTOTUNE,
)
# No augmentation on the validation set — measure the real thing
val_ds = val_ds  # left untouched

External links

Exercise

같은 model + schedule 로 CIFAR-10 을 3 augmentation 전략 학습 — vanilla (flip + rotation), MixUp(0.2), CutMix(1.0). 셋 다 train AND val accuracy 곡선을 epoch 50 까지 plot. 흥미로운 신호는 최종 val accuracy 만이 아니라 train/val 격차야. 어느 전략이 그 격차를 제일 좁히는지, MixUp 효과가 일찍 나오는지 늦게 나오는지 메모.
Hint
MixUp 은 train accuracy 가 더 나빠 보여 (섞인 label 은 fit 하기 어려움), 근데 validation 은 더 좋아 — 그 divergence 가 버그가 아니라 regularization 이 일하는 거야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.