2

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.

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.: 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
devautor
  • 2,506
  • 4
  • 21
  • 31

1 Answers1

2

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.

Sergii Gryshkevych
  • 4,029
  • 1
  • 25
  • 42
  • Thanks, it does solve the dimension mismatch; but can you comment on that baseline error of 99.23%, I am still getting the exact same! – devautor Jan 26 '17 at 09:35
  • It is difficult to say anything about the error without any details. Are you talking about the training error or the test one? What about your data set? Provide a minimal reproducible example and all necessary details to get constructive feedback on the error issue. I would suggest to do that in a new question, this one is about dimensions. – Sergii Gryshkevych Jan 26 '17 at 10:03
  • Sure, I would try on my own for some time and then would do it, if needed :) – devautor Jan 26 '17 at 10:04