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

실전 — augmentation 포함 image pipeline

~8 min · data

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

End-to-end vision pipeline: image_dataset_from_directory → cache → batch → shuffle → prefetch → model 안의 Rescaling + RandomFlip + RandomRotation. 한 spec 으로 학습 / inference / deploy 다 동일한 전처리.

구조: dataset 준비 (load + cache + prefetch) → augmentation layer 들 model 에 박기 → train. inference 환경: 같은 model.predict() 호출하면 학습 시 적용한 rescaling 그대로, augmentation 은 자동 OFF.

Code

import keras
from keras import layers

# Data augmentation layers (only active during training)
augmentation = keras.Sequential([
    layers.RandomFlip("horizontal"),
    layers.RandomRotation(0.1),
    layers.RandomZoom(0.1),
])

# Model with preprocessing built in
model = keras.Sequential([
    keras.Input(shape=(224, 224, 3)),
    layers.Rescaling(1.0 / 255.0),   # Normalize
    augmentation,                       # Augment
    layers.Conv2D(32, 3, activation="relu"),
    layers.MaxPooling2D(2),
    layers.Conv2D(64, 3, activation="relu"),
    layers.MaxPooling2D(2),
    layers.GlobalAveragePooling2D(),
    layers.Dense(128, activation="relu"),
    layers.Dense(5, activation="softmax"),
])

model.compile(optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"])
model.fit(train_ds, validation_data=val_ds, epochs=20)

External links

Exercise

전체 pipeline 빌드 — dog/cat 이미지 폴더 → image_dataset_from_directory → cache/prefetch → Rescaling + augmentation + small CNN 모델 → 학습 → 저장. .keras 파일 로드 + raw image 로 predict 해서 deploy.

Progress

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

댓글 0

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

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