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

필수 layer와 activation 함수

~11 min · layers, activations, relu, gelu

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

모든 model에서 쓸 어휘

Keras에 layer가 100개 넘지만 실제로 자주 쓰는 건 작은 핵심 그룹이야. 이걸 외우면 나머지는 따라와.

핵심 layer: Dense (완전연결), Conv2D (이미지 convolution), BatchNormalization, Dropout, MaxPooling2D, GlobalAveragePooling2D, Flatten, Reshape.

Activation 함수: relu (hidden layer 기본), gelu (transformer hidden), swish (EfficientNet), tanh (LSTM/GRU cell), sigmoid (이진 출력), softmax (다중 출력 — 단 numerical stability 위해 loss에서 from_logits=True랑 짝).

from_logits=True 관용구: SparseCategoricalCrossentropyBinaryCrossentropy 쓸 때는 항상 from_logits=True 설정하고, model 출력 layer에서 softmax/sigmoid 빼. loss가 안에서 numerically stable한 log-sum-exp 공식으로 activation 계산해. softmax 다음에 log 취하면 극단 logit에서 NaN 생길 수 있거든.

Code

Core layers at a glance·python
from keras import layers
import tensorflow as tf

# Fully connected
dense = layers.Dense(units=128, activation='relu',
                     kernel_regularizer=tf.keras.regularizers.l2(0.01))

# Image convolution
conv = layers.Conv2D(filters=64, kernel_size=3, padding='same',
                     activation='relu')

# Regularization
bn = layers.BatchNormalization()
drop = layers.Dropout(rate=0.3)

# Pooling
max_pool = layers.MaxPooling2D(pool_size=2, strides=2)
global_avg = layers.GlobalAveragePooling2D()  # (b, h, w, c) → (b, c)

# Shape manipulation
flat = layers.Flatten()
reshape = layers.Reshape((7, 7, 32))
Activation guide·python
from keras import layers

# Hidden (MLP/CNN): relu, gelu (transformers), swish (EfficientNet)
relu = layers.Activation('relu')
gelu = layers.Activation('gelu')
swish = layers.Activation('swish')

# Hidden (RNN cells): tanh
# Output (binary): sigmoid — but use from_logits=True in loss
# Output (multi-class): softmax — but use from_logits=True in loss
# Output (regression): None (linear)

# LeakyReLU fixes "dead neuron" problem
leaky = layers.LeakyReLU(alpha=0.1)

Progress

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

댓글 0

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

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