lenet5(keras)识别mnist 收敛速度很慢
在用lenet5做mnist识别时,网络收敛速度很慢经过100多轮训练仍在在50%准确率徘徊;参考其他人一轮变可以达到95+%的代码,进行修改原始结构及参数:(图像也没有处理为0-1浮点数)def get_lenet5(self):input = Input(shape=(cf.Img_size, cf.Img_size, cf.Img_channels)...
·
在用lenet5做mnist识别时,网络收敛速度很慢经过100多轮训练仍在在50%准确率徘徊;参考其他人一轮变可以达到95+%的代码,进行修改
原始结构及参数:(图像也没有处理为0-1浮点数)
def get_lenet5(self):
input = Input(shape=(cf.Img_size, cf.Img_size, cf.Img_channels))
conv1 = Conv2D(cf.Conv1_chs, kernel_size=cf.Conv1_kernel_size, padding='same', activation='relu')(input)
pool1 = MaxPooling2D(2, 2, padding='same')(conv1)
conv2 = Conv2D(cf.Conv2_chs, kernel_size=cf.Conv2_kernel_size, padding='same', activation='relu')(pool1)
pool2 = MaxPooling2D(2, 2, padding='same')(conv2)
flat = Flatten()(pool2)
fc1 = Dense(cf.Fc1_size, activation='relu')(flat)
fc2 = Dense(cf.Fc2_size, activation='relu')(fc1)
output = Softmax()(fc2)
model = Model(inputs=input, outputs=output)
model.compile(optimizer=Adam(lr=cf.Learning_rate), loss='categorical_crossentropy', metrics=['accuracy'])
return model
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 28, 28, 1) 0
_________________________________________________________________
conv2d_1 (Conv2D) (None, 28, 28, 20) 520
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 14, 14, 20) 0
_________________________________________________________________
conv2d_2 (Conv2D) (None, 14, 14, 50) 25050
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 7, 7, 50) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 2450) 0
_________________________________________________________________
dense_1 (Dense) (None, 500) 1225500
_________________________________________________________________
dense_2 (Dense) (None, 10) 5010
_________________________________________________________________
softmax_1 (Softmax) (None, 10) 0
=================================================================
修改:
1)将图像处理为浮点数
x_train,x_test = x_train/255,x_test/255
2)去掉最后单独的softmax层,将第二层全连接激活方式改为softmax
fc2 = Dense(cf.Fc2_size, activation='softmax')(fc1)
model = Model(inputs=input, outputs=fc2)
3)经过测试,学习率设置为3e-3
更多推荐
所有评论(0)