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

다중 입력·다중 출력

~8 min · functional

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

다중 입력: inputs = [keras.Input(shape=...), keras.Input(shape=...)] 두 개 만들어 각각 layer 적용 후 keras.layers.concatenate 또는 add 로 합쳐. model = keras.Model(inputs, outputs) 의 inputs 자리에 list 넘기면 끝.

다중 출력: outputs = [output_a, output_b] list 로 넘겨. compile 시 loss 도 list 또는 dict — loss=['mse', 'binary_crossentropy']. 각 head 마다 다른 loss / weight 가능. 이게 multi-task learning 의 자연스러운 표현.

Code

# Multi-input, multi-output ticket classification
title_input = keras.Input(shape=(100,), name="title")
body_input = keras.Input(shape=(500,), name="body")
tags_input = keras.Input(shape=(12,), name="tags")

# Process each branch
title_features = layers.Dense(64, activation="relu")(title_input)
body_features = layers.Dense(128, activation="relu")(body_input)
tags_features = layers.Dense(32, activation="relu")(tags_input)

# Merge branches
x = layers.concatenate([title_features, body_features, tags_features])
x = layers.Dense(128, activation="relu")(x)

# Multiple outputs
priority = layers.Dense(3, activation="softmax", name="priority")(x)
department = layers.Dense(5, activation="softmax", name="department")(x)

model = keras.Model(
    inputs=[title_input, body_input, tags_input],
    outputs=[priority, department],
)

External links

Exercise

(image, age) 받아 (class_logits, regression_score) 내는 model 짜. named input/output 사용. 두 loss 로 compile. synthetic data 로 한 epoch 학습.

Progress

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

댓글 0

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

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