TensorFlow 초기화기 — Keras 초기화기의 TensorFlow 문서
TensorFlow 초기화기 — Keras 초기화기의 TensorFlow 문서
TensorFlow 의 tf.keras.initializers 네임스페이스는 Keras 초기화기의 Python API 문서예요. tf.keras.layers 의 레이어들이 기본적으로 사용하는 초기화기와, 직접 만들 수 있는 방법을 안내해요.
핵심 내용
- 각 초기화기 클래스는
__call__(shape, dtype=None)을 구현해 주어진 형상의 텐서를 반환해요. tf.keras.initializers.get(identifier)로 문자열·객체·함수를 초기화기로 해석해요.- Dense·Conv·Embedding 같은 레이어의
kernel_initializer에 바로 주입해요.
import tensorflow as tf
init = tf.keras.initializers.HeNormal()
w = init(shape=(256, 512))
사용 팁
- 팬인(fan_in)·팬아웃(fan_out) 계산은 레이어가 알아서 하고, 초기화기는 형상만 받아요.
- 사용자 정의 초기화기를 만들려면
tf.keras.initializers.Initializer를 상속해__call__만 구현하면 돼요. - 대부분의 레이어는 기본 초기화기가 있으니, 특별한 이유가 없으면 생략해도 돼요.