Closed choidam closed 4 years ago
Weight Initialization
he
tf.keras.initializers.he_normal(
seed=None
)
def mlp_model():
model = Sequential()
model.add(Dense(50, input_shape = (784, ), kernel_initializer='he_normal')) # use he_normal initializer
model.add(Activation('sigmoid'))
model.add(Dense(50, kernel_initializer='he_normal')) # use he_normal initializer
model.add(Activation('sigmoid'))
model.add(Dense(50, kernel_initializer='he_normal')) # use he_normal initializer
model.add(Activation('sigmoid'))
model.add(Dense(50, kernel_initializer='he_normal')) # use he_normal initializer
model.add(Activation('sigmoid'))
model.add(Dense(10, kernel_initializer='he_normal')) # use he_normal initializer
model.add(Activation('softmax'))
sgd = optimizers.SGD(lr = 0.001)
model.compile(optimizer = sgd, loss = 'categorical_crossentropy', metrics = ['accuracy'])
return model
위의 예시는 일반
Dense Layer
에만 적용되는듯 ..CNN
에 적용은 좀 더 찾아보자.
코드엔 추가 해보았다.
동일한 라이브러리에서 제대로 추가하지 않으면 오류 발생. 유의하자 ..
from tensorflow.keras.layers import Conv2D, MaxPooling2D, ReLU, BatchNormalization, Dropout
from tensorflow.keras import optimizers
from keras.optimizers import adam
model2 = Sequential()
model2.add(Conv2D(50, (3, 3),
padding='same',
input_shape=X_train.shape[1:],
kernel_initializer='he_normal'))
model2.add(BatchNormalization())
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size = (2,2)))
model2.add(Conv2D(filters = 50,
kernel_size = (3,3),
strides = (1,1),
padding = 'same',
kernel_initializer='he_normal'))
model2.add(BatchNormalization())
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size = (2,2)))
model2.add(Flatten())
model2.add(Dense(50, activation = 'relu', kernel_initializer='he_normal'))
model2.add(Dropout(0.5))
model2.add(Dense(10, activation = 'softmax', kernel_initializer='he_normal'))
adam = optimizers.Adam(lr = 0.001)
model2.compile(loss = 'categorical_crossentropy',
optimizer = adam,
metrics = ['accuracy'])
BatchNormalization
, he
, dropout
, relu
, adam
모두 적용해보았으나 성능이 얼마나 좋아졌는지는 알 수가 없다 .. 파라미터 개수가 엄청 많아져서 오히려 떨어졌을 것 같기도 .. 일단 빨리 실행해야 알 듯
Weight Initialization
Xavier
,He
Initialization 사용해서 가중치 초기화하기Batch Normalization
Dropout