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

MNIST classifier 빌드

~8 min · sequential

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

고전 hello-world: MNIST 손글씨 0–9. keras.datasets.mnist.load_data() 로 데이터 받고, normalize (255 로 나누기), 그다음 Sequential model: Flatten → Dense(128, relu) → Dropout(0.2) → Dense(10, softmax).

compile 에 optimizer='adam', loss='sparse_categorical_crossentropy' (label 이 int 라서 sparse), metrics=['accuracy']. fit(x_train, y_train, epochs=5, validation_split=0.1). 5 epoch 후 test accuracy 보통 97-98%. 처음 model 인데 이정도면 나쁘지 않아.

Code

import keras
from keras import layers

# 1. Load data
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()

# 2. Normalize pixel values to [0, 1]
x_train = x_train.astype("float32") / 255.0
x_test = x_test.astype("float32") / 255.0

# 3. Build model
model = keras.Sequential([
    keras.Input(shape=(28, 28)),
    layers.Flatten(),
    layers.Dense(128, activation="relu"),
    layers.Dropout(0.2),
    layers.Dense(10, activation="softmax"),
])

# 4. Compile
model.compile(
    optimizer="adam",
    loss="sparse_categorical_crossentropy",
    metrics=["accuracy"],
)

# 5. Train
model.fit(x_train, y_train, epochs=5, validation_split=0.1)

# 6. Evaluate
test_loss, test_acc = model.evaluate(x_test, y_test)
print(f"Test accuracy: {{test_acc:.4f}}")  # ~97.5%

External links

Exercise

위 MNIST classifier 구현해서 test accuracy 97% 이상. 이제 일부러 망가뜨려 — 'categorical_crossentropy' (잘못) 로 바꿔서 에러 봐. 실패 모드 안에 lesson 이 있어.

Progress

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

댓글 0

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

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