Xavier Initialization
Gradient Vanishing 현상을 완화 하기 위해서 weight 를 초기화 할 때,
Sigmoid와 같은 S자 함수의 경우, 가장 중요한 것은 출력값들이 표준 정규 분포 형태를 갖게 하는 것이다.
출력값들이 표준 정규분포 형태를 갖게 되어야 안정적으로 학습이 가능하기 때문이다.
Xavier(사비에르) Initialization 방법은, 단순히 가중치를 작은 값의 표준편차를 갖는 형태로 초기화 하는 것이 아닌, 보다 발전된 방법이다.
Xavier Initialization 방법은 표준 정규분포로 초기화 된 가중치를 1/입력개수 제곱근으로 나누어주면 된다.
w = np.random.randn(n_input, n_output) / sqrt(1/n_input)
Xavier 이용 XOR 문제 풀기
xor = {'x1':[0,0,1,1], 'x2':[0,1,0,1], 'y':[0,1,1,0]}
XOR = pd.DataFrame(xor)
X = XOR.drop('y', axis=1)
y = XOR.y
ip = Input(shape=(2,))
n= Dense(2, activation='sigmoid')(ip)
n = Dense(1, activation='linear')(n)
model = Model(inputs=ip, outputs=n)
'''XOR 문제 xavier이용 해서 weight 변별력 주기
'''
weights = model.get_weights()
xavier_w12 = np.random.randn(2,2) /np.sqrt(2)
xavier_weights = weights.copy()
xavier_weights[0] = xavier_w12
model.set_weights(xavier_weights)
model.compile(loss='mse', optimizer='rmsprop')
model.fit(X,y, epochs=1400,verbose=0)
print(model.predict(X))
'DeepLearning' 카테고리의 다른 글
DeepLearning - 컨볼루션 신경망 다중 클래스 분류 (0) | 2022.10.31 |
---|---|
DeepLearning - keras initializer 종류 (0) | 2022.10.31 |
DeepLearning - 신경망 결합 concatenate (0) | 2022.10.31 |
DeepLearning - Tensorflow 신경망 원리 (0) | 2022.10.30 |
DeepLearning - Tensorflow (Kaggle, Fashion MNIST) (0) | 2022.10.30 |