问题描述
我正在使用Keras库构建此深度学习模型:INPUT(深度= 1,高度= 15,宽度= 27)-> CONV [深度= 8](高度= 4,宽度= 27)-> POOL( height = 2,width = 1)->(回归)输出.
I am using Keras library to build this deep learning model: INPUT(depth=1, height=15, width=27) -> CONV[depth=8](height=4, width=27) -> POOL(height=2, width=1) -> (Regression) output.
我期望卷积2d_1的输出形状为(None,8,12,1),因此,pooling2d_1的输出形状为(None,8,6,1);而我分别得到(None,8,15,27)和(None,8,7,27).
I expect the ouput shape from convolution2d_1 to be (None, 8, 12, 1) and thence, the ouput shape from pooling2d_1 to be (None, 8, 6, 1); while I am getting (None, 8, 15, 27) and (None, 8, 7, 27) respectively.
我在做什么或在这里解释错误?
What am I doing or interpreting wrong here?
P.S .:另外,此设置还会产生基准错误:99.23%!
P.S.: Also, this setting gives a Baseline Error: 99.23%!
print "SHAPE OF INPUT IS:", num_train_3D, depth, height, width
inp = Input(shape=(depth, height, width))
conv_1 = Convolution2D(8, 4, 27, border_mode='same', activation='relu')(inp)
pool_1 = MaxPooling2D(pool_size=(2, 1))(conv_1)
''' Now flatten to 1D, apply FC -> ReLU (with dropout) -> softmax '''
flat = Flatten()(pool_1)
out = Dense(1)(flat) #regression
model = Model(input=inp, output=out) # To define a model, just specify its input and output layers
print "Model Summary:"
print model.summary()
===================================
=====================================
SHAPE OF INPUT IS: 53745 1 15 27
Model Summary:
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_1 (InputLayer) (None, 1, 15, 27) 0
____________________________________________________________________________________________________
convolution2d_1 (Convolution2D) (None, 8, 15, 27) 872 input_1[0][0]
____________________________________________________________________________________________________
maxpooling2d_1 (MaxPooling2D) (None, 8, 7, 27) 0 convolution2d_1[0][0]
____________________________________________________________________________________________________
flatten_1 (Flatten) (None, 1512) 0 maxpooling2d_1[0][0]
____________________________________________________________________________________________________
dense_1 (Dense) (None, 1) 1513 flatten_1[0][0]
====================================================================================================
Total params: 2,385
Trainable params: 2,385
Non-trainable params: 0
推荐答案
将border_mode='same'
更改为border_mode='valid'
.边界模式same
向输入添加零填充,以确保卷积层的输出与其输入具有相同的形状.使用边界模式valid
时,仅在输入和过滤器完全重叠的地方执行卷积.
Change border_mode='same'
to border_mode='valid'
. Border mode same
adds zero padding to the input to make sure that the output of the convolutional layer has the same shape as its input. With border mode valid
convolution is performed only where the input and the filter fully overlap.
这篇关于Keras-CNN模型摘要尺寸解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!