基础_cifar10_序贯

今天的基础研究主要是在cifar10数据集上解决一下几个问题:

1、从头开始,从最简单的序贯开始,尝试model的构造;
2、要将模型打印出来。最好是能够打印出图片,否则也要summary;
3、尝试对例子的参数进行分析,得出初步修改意见。

1、构建模型
num_classes =
data_augmentation =
save_dir = os.path.join(os.getcwd(), ], ],
x_test /=

, )

)
])
])


2、要将模型打印出来,目前只有本地才有图片。这个图片也可以本地看。
Using TensorFlow backend.
x_train shape: (50000, 32, 32, 3)
50000 train samples
10000 test samples
_________________________________________________________________
Layer (type)                 Output Shape              Param #  
=================================================================
conv2d_1 (Conv2D)            (None, 32, 32, 32)        896      
_________________________________________________________________
activation_1 (Activation)    (None, 32, 32, 32)        0        
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 30, 30, 32)        9248     
_________________________________________________________________
activation_2 (Activation)    (None, 30, 30, 32)        0        
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 15, 15, 32)        0        
_________________________________________________________________
dropout_1 (Dropout)          (None, 15, 15, 32)        0        
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 15, 15, 64)        18496    
_________________________________________________________________
activation_3 (Activation)    (None, 15, 15, 64)        0        
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 13, 13, 64)        36928    
_________________________________________________________________
activation_4 (Activation)    (None, 13, 13, 64)        0        
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 6, 6, 64)          0        
_________________________________________________________________
dropout_2 (Dropout)          (None, 6, 6, 64)          0        
_________________________________________________________________
flatten_1 (Flatten)          (None, 2304)              0        
_________________________________________________________________
dense_1 (Dense)              (None, 512)               1180160  
_________________________________________________________________
activation_5 (Activation)    (None, 512)               0        
_________________________________________________________________
dropout_3 (Dropout)          (None, 512)               0        
_________________________________________________________________
dense_2 (Dense)              (None, 10)                5130     
_________________________________________________________________
activation_6 (Activation)    (None, 10)                0        
=================================================================
Total params: 1,250,858
Trainable params: 1,250,858
Non-trainable params: 0
_________________________________________________________________
(2065, 635, 4)
Using real-time data augmentation.
WARNING:tensorflow:Variable *= will be deprecated. Use variable.assign_mul if you want assignment to the variable value or 'x = x * y' if you want a new python Tensor object.
Epoch 1/3
138/1563 [=>........

大图:

基础_cifar10_序贯

 

3、尝试对例子的参数进行分析,得出初步修改意见
从这个序贯模型的建立过程中,其模型大概是这样的:
第一段是
model.add(Conv2D(32, (3, 3), padding='same',input_shape=x_train.shape[1:]))
model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
基本上相当于卷积->激活->卷积->激活->maxPooling->dropout
然后
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
几乎是原样的来了一遍,唯一不同的是变成了64个一组。
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))
最后,到输出阶段了,应该是要准备输出了。
在这个地方,应该触及DL这门技术的核心了,就是我应该构造增益的网络?又怎样根据生成的结果来调整网络。迁移我在图像处理方面的知识,我首先是知道了基础的工具,然后有了很多实际的经验,这样才能够在拿到问题的第一时间,有初步的设想。
更简单的网络代表可以更快 地训练,在我的研究过程中,需要寻找的并不是我们的网络能够复杂到什么程度—而是怎样简单的网络就可以完成目标,达到既定的acc。首先可能是90%到95%,逐渐地去接触更多东西。在cifar-10上要起码达到这个结果。

当然我知道增加epoch,一般时候能够提高准确率,当然也会过拟合;另一个方向,如果我缩小数据,比如在上面的例子中,不添加64位层,结果是这样:
model = Sequential()
model.add(Conv2D(32, (3, 3), padding='same',
                 input_shape=x_train.shape[1:]))
model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))

model2 = Sequential()
model2.add(Conv2D(32, (3, 3), padding='same',
                 input_shape=x_train.shape[1:]))
model2.add(Activation('relu'))
model2.add(Conv2D(32, (3, 3)))
model2.add(Activation('relu'))
model2.add(MaxPooling2D(pool_size=(2, 2)))
model2.add(Dropout(0.25))

model2.add(Flatten())
model2.add(Dense(512))
model2.add(Activation('relu'))
model2.add(Dropout(0.5))
model2.add(Dense(num_classes))
model2.add(Activation('softmax'))


Test loss: 0.8056231224060059
Test accuracy: 0.7182
10000/10000 [==============================] - 2s 161us/step
Test loss2: 0.9484411451339722
Test accuracy2: 0.6764


最后,在《NN&DL》中反复被提及的一点,我也实际体会到了:训练需要时间,你可以先去做其它的事情。
到此,我认为《基础_cifar10_序贯》可以结束。




上一篇:BOM (Browser Object Model) 浏览器对象模型


下一篇:深入学习jQuery鼠标事件