import os os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"]="1"import keras from keras.datasets import cifar10 from keras import backend as K from keras.layers import Input, Conv2D, GlobalAveragePooling2D, Dense, BatchNormalization, Activation, MaxPooling2D from keras.models import Model from keras.layers import concatenate,Dropout,Flattenfrom keras import optimizers,regularizers from keras.preprocessing.image import ImageDataGenerator from keras.initializers import he_normal from keras.callbacks import LearningRateScheduler, TensorBoard, ModelCheckpointnum_classes =10 batch_size =64# 64 or 32 or other epochs =300 iterations =782 DROPOUT=0.5# keep 50% CONCAT_AXIS=3 weight_decay=1e-4 DATA_FORMAT='channels_last'# Theano:'channels_first' Tensorflow:'channels_last' log_filepath ='./alexnet'
x = Conv2D(96,(3,3),strides=(1,1),padding='same',activation='relu',kernel_initializer='uniform')(img_input)# valid
其它部分代码同 alexnet
参数量如下(增加了挺多的):
Total params: 87,650,186 Trainable params: 87,650,186 Non-trainable params: 0
alexnet Total params: 21,622,154
因为 down sampling 的次数少了3次,最后接 fc 层 的feature map 的 resolution 会大 8×8倍,而且 CNN 的参数量大多都集中在 fc 层的结构,所以参数量变多了可想而知! 叫 slim 的原因是缩减了一些 down sampling 层,如果是全卷积网络,参数量会减少或者不变!
x = Conv2D(96,(3,3),strides=(1,1),padding='same',activation='relu',kernel_initializer='he_normal',kernel_regularizer=regularizers.l2(weight_decay))(img_input)# valid
其它代码同 alexnet_slim
参数量如下(不变):
Total params: 87,650,186 Trainable params: 87,650,186 Non-trainable params: 0
alexnet Total params: 21,622,154
alexnet_slim Total params: 87,650,186
结果分析如下 training accuracy 和 training loss
test accuracy 和 test loss
精度上到了 92%,过拟合现象得到了缓解
2.4 alexnet_thinner
alexnet_thinner_2 在 alexnet_slim_regular 的基础上,将网络所有的 filters number 改为原来的 1/2,包括 fully connection, alexnet_thinner_4 在 alexnet_slim_regular 的基础上,将网络所有的 filters number 改为原来的 1/4,包括 fully connection。