Skip to content

Commit

Permalink
Merge pull request wepe#5 from poyuwu/master
Browse files Browse the repository at this point in the history
compatible with keras-0.3.0
  • Loading branch information
wepe committed Dec 6, 2015
2 parents cbd0e18 + 4850b92 commit e3cd632
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions DeepLearning Tutorials/keras_usage/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@
#border_mode可以是valid或者full,具体看这里说明:http://deeplearning.net/software/theano/library/tensor/nnet/conv.html#theano.tensor.nnet.conv.conv2d
#激活函数用tanh
#你还可以在model.add(Activation('tanh'))后加上dropout的技巧: model.add(Dropout(0.5))
model.add(Convolution2D(4, 1, 5, 5, border_mode='valid'))
model.add(Convolution2D(4, 5, 5, border_mode='valid',input_shape=data.shape[-3:]))
model.add(Activation('tanh'))


#第二个卷积层,8个卷积核,每个卷积核大小3*3。4表示输入的特征图个数,等于上一层的卷积核个数
#激活函数用tanh
#采用maxpooling,poolsize为(2,2)
model.add(Convolution2D(8,4, 3, 3, border_mode='valid'))
model.add(Convolution2D(8, 3, 3, border_mode='valid'))
model.add(Activation('tanh'))
model.add(MaxPooling2D(poolsize=(2, 2)))
model.add(MaxPooling2D(pool_size=(2, 2)))

#第三个卷积层,16个卷积核,每个卷积核大小3*3
#激活函数用tanh
#采用maxpooling,poolsize为(2,2)
model.add(Convolution2D(16, 8, 3, 3, border_mode='valid'))
model.add(Convolution2D(16, 3, 3, border_mode='valid'))
model.add(Activation('tanh'))
model.add(MaxPooling2D(poolsize=(2, 2)))
model.add(MaxPooling2D(pool_size=(2, 2)))

#全连接层,先将前一层输出的二维特征图flatten为一维的。
#Dense就是隐藏层。16就是上一层输出的特征图个数。4是根据每个卷积层计算出来的:(28-5+1)得到24,(24-3+1)/2得到11,(11-3+1)/2得到4
#全连接有128个神经元节点,初始化方式为normal
model.add(Flatten())
model.add(Dense(16*4*4, 128, init='normal'))
model.add(Dense(128, init='normal'))
model.add(Activation('tanh'))


#Softmax分类,输出是10类别
model.add(Dense(128, 10, init='normal'))
model.add(Dense(10, init='normal'))
model.add(Activation('softmax'))


Expand Down

0 comments on commit e3cd632

Please sign in to comment.