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

Keras Preprocessing Layer

~8 min · data

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

모델은 engineering 의 30%, data pipeline 이 나머지 70%. Keras 3 는 모델 graph *안에서* 돌아가는 preprocessing layer (image augmentation, text vectorization, normalization) 가 강력해 — 저장된 model 에 같이 따라가. 거기에 `tf.data`, `torch.DataLoader`, `grain` 붙이는 법까지.

Keras 3 의 차별점 — 전처리도 *layer*. Rescaling, Normalization, RandomFlip, RandomRotation, TextVectorization, IntegerLookup 등. 모델 graph 안에서 동작 → saved model 에 동행 → deploy 시 동일 전처리 자동 보장.

두 패턴: (1) 모델 일부로 (graph 에 박힘) — deploy 안전, (2) tf.data pipeline 에서 (학습 속도 ↑) — deploy 시 직접 또 박아야. 권장: 가능하면 (1).

Code

# Normalization: learns mean/variance from data
normalizer = layers.Normalization()
normalizer.adapt(training_data)  # Must see data first

# Rescaling: simple linear transform
rescaler = layers.Rescaling(1.0 / 255.0)

# TextVectorization: text → integer tokens
vectorizer = layers.TextVectorization(
    max_tokens=20000,
    output_sequence_length=200,
)
vectorizer.adapt(text_data)

# Put inside the model
model = keras.Sequential([
    rescaler,                                    # Preprocessing
    layers.Conv2D(32, 3, activation="relu"),  # Model layers
    layers.GlobalAveragePooling2D(),
    layers.Dense(10, activation="softmax"),
])

External links

Exercise

Rescaling + RandomFlip 을 첫 두 layer 로 가지는 모델 짜. 학습 / 저장 / 로드. raw [0,255] image 로 predict, rescaling 동작 확인 (에러 없이 sane 출력).

Progress

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

댓글 0

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

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