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

Hyperparameter tuning

~8 min · advanced

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

Keras tutorial 졸업한 사람 vs 실제로 ship 하는 사람 가르는 패턴들. KerasTuner 로 hyperparameter sweep, mixed-precision (FP16/BF16) 으로 2-3 배 속도, multi-GPU distribution strategy, post-training quantization, knowledge distillation, training 이 조용히 망가질 때의 debugging playbook.

KerasTuner — hyperparameter sweep 자동화. RandomSearch / BayesianOptimization / Hyperband 알고리즘 제공. tuner = keras_tuner.RandomSearch(build_model, max_trials=10) 같이 search 객체 만들고 tuner.search(x, y, ...).

build_model(hp) 가 hyperparameter 객체 받아 model 반환. hp.Int('units', 32, 256, step=32) 같이 search space 정의. tuner 가 trial 마다 다른 값 시도, 가장 좋은 model 반환.

Code

import keras_tuner

def build_model(hp):
    model = keras.Sequential([
        keras.Input(shape=(784,)),
        layers.Dense(
            units=hp.Int("units", min_value=32, max_value=512, step=32),
            activation="relu",
        ),
        layers.Dropout(hp.Float("dropout", 0.0, 0.5, step=0.1)),
        layers.Dense(10, activation="softmax"),
    ])
    model.compile(
        optimizer=keras.optimizers.Adam(
            hp.Float("lr", 1e-4, 1e-2, sampling="log")
        ),
        loss="sparse_categorical_crossentropy",
        metrics=["accuracy"],
    )
    return model

# Search strategies
tuner = keras_tuner.BayesianOptimization(
    build_model, objective="val_accuracy", max_trials=20,
)
tuner.search(x_train, y_train, epochs=10, validation_split=0.2)
best_model = tuner.get_best_models()[0]

External links

Exercise

MNIST 의 작은 MLP 튜닝 — layer 수 (1-4), unit per layer (32-256), learning rate (1e-4 ~ 1e-2). Hyperband (max_epochs=20). best model 을 직접 튜닝한 baseline 과 비교.

Progress

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

댓글 0

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

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