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

Skip connection 과 residual block

~8 min · functional

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

Skip connection 의 코드 패턴: x = Conv2D(...)(input); x = Conv2D(...)(x); output = keras.layers.add([x, input]). 즉 두 layer 통과한 결과에 *원본 입력을 더해서* 다음으로 넘김. ResNet 의 핵심 발상.

왜 효과 있나? (1) gradient 가 identity path 통해 흘러서 vanishing 완화. (2) layer 가 *residual* (잔차) 만 학습하면 됨 — identity 위에 작은 보정. (3) 깊이 2x 해도 수렴 가능. 50 layer ResNet 이 그래서 가능했어.

Code

# A simple residual block
def residual_block(x, filters):
    shortcut = x  # Save the input

    x = layers.Dense(filters, activation="relu")(x)
    x = layers.Dense(filters)(x)

    # Add the skip connection
    x = layers.add([x, shortcut])
    x = layers.Activation("relu")(x)
    return x

# Use it in a model
inputs = keras.Input(shape=(128,))
x = layers.Dense(128, activation="relu")(inputs)
x = residual_block(x, 128)
x = residual_block(x, 128)
outputs = layers.Dense(10, activation="softmax")(x)
model = keras.Model(inputs, outputs)

External links

Exercise

ResNet block 하나 짜 — input → Conv → BN → ReLU → Conv → BN → add(input) → ReLU. Functional API 로. output shape 가 input shape 과 일치 확인 (안 맞으면 shortcut 에 1×1 conv 추가).

Progress

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

댓글 0

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

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