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

Functional 패턴

~8 min · functional

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

핵심 패턴 한 줄 요약: output = layer(input). Layer 를 *함수처럼* 호출. x = Dense(64)(inputs); x = Dense(32)(x); outputs = Dense(10)(x); model = keras.Model(inputs, outputs). Sequential 보다 살짝 verbose 하지만 graph 가 코드에 그대로 박혀.

핵심 인지 전환: layer 인스턴스 = 함수. dense = Dense(64) 만들고 두 군데에서 dense(x1)·dense(x2) 호출하면 *같은 weight* 공유. 이게 shared layer 의 자연스러운 표현.

Code

import keras
from keras import layers

# Step 1: Define input
inputs = keras.Input(shape=(784,))

# Step 2: Chain layers
x = layers.Dense(256, activation="relu")(inputs)
x = layers.Dropout(0.3)(x)
x = layers.Dense(128, activation="relu")(x)
outputs = layers.Dense(10, activation="softmax")(x)

# Step 3: Create model
model = keras.Model(inputs=inputs, outputs=outputs, name="my_classifier")
model.summary()

External links

Exercise

MNIST Sequential 모델을 Functional 로 변환. model.summary() 동일한지 확인. 그다음 공유 Dense layer 만들어 두 다른 입력에 적용 — 둘이 weight 공유하는지 len(model.weights) 로 확인.

Progress

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

댓글 0

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

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