2
$\begingroup$
model = Sequential()
model.add(Conv2D(64, (1, 1), activation='relu', input_shape=(64,64,3)))
model.add(Conv2D(64, (5,5), strides=(2,2), padding='same'))
model.add(MaxPooling2D(pool_size=3, strides=(2,2)))
model.add(Conv2D(64, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (3, 3), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (3, 3), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (3, 3), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(128, (1,1),
                strides=(2,2),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (3,3),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(128, (3,3),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (1,1),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (3,3),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (1,1),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (3,3), 
                strides=(1,1), 
                padding='valid'))

model.add(AveragePooling2D(pool_size=2, strides=(2,2), padding='valid'))
model.add(Conv2D(1,1,200))
model.add(Flatten())
model.add(Activation('softmax'))
$\endgroup$
2
$\begingroup$

You are using too many layers and you run out of spatial space.

Most of your convolutional layers use "valid" padding, meaning that the convolution is performed only on actual "pixels" without any padding and as a result the spatial dimensions of the output are smaller than the input.

I've marked down where it happens in your script:

model = Sequential()
model.add(Conv2D(64, (1, 1), activation='relu', input_shape=(64,64,3)))
model.add(Conv2D(64, (5,5), strides=(2,2), padding='same'))
model.add(MaxPooling2D(pool_size=3, strides=(2,2)))
model.add(Conv2D(64, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (3, 3), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (3, 3), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(64, (3, 3), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(128, (1,1),
                strides=(2,2),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (3,3),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (1, 1), 
                          strides=(1,1), 
                          activation='relu',
                          padding='valid' ))
model.add(Conv2D(128, (3,3),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (1,1),
                strides=(1,1),
                activation='relu',
                padding='valid'))

model.summary() # This is where it happens - The output of this layer is of shape (1,1,128)

model.add(Conv2D(128, (3,3),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (1,1),
                strides=(1,1),
                activation='relu',
                padding='valid'))
model.add(Conv2D(128, (3,3), 
                strides=(1,1), 
                padding='valid'))

model.add(AveragePooling2D(pool_size=2, strides=(2,2), padding='valid'))
model.add(Conv2D(1,1,200))
model.add(Flatten())
model.add(Activation('softmax'))

You can use the Keras "summary" method to investigate your model. For example, the output from the script I've written here is:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_1 (Conv2D)            (None, 64, 64, 64)        256       
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 32, 32, 64)        102464    
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 15, 15, 64)        0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 15, 15, 64)        4160      
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 13, 13, 64)        36928     
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 13, 13, 64)        4160      
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 11, 11, 64)        36928     
_________________________________________________________________
conv2d_7 (Conv2D)            (None, 11, 11, 64)        4160      
_________________________________________________________________
conv2d_8 (Conv2D)            (None, 9, 9, 64)          36928     
_________________________________________________________________
conv2d_9 (Conv2D)            (None, 5, 5, 128)         8320      
_________________________________________________________________
conv2d_10 (Conv2D)           (None, 3, 3, 128)         147584    
_________________________________________________________________
conv2d_11 (Conv2D)           (None, 3, 3, 128)         16512     
_________________________________________________________________
conv2d_12 (Conv2D)           (None, 1, 1, 128)         147584    
_________________________________________________________________
conv2d_13 (Conv2D)           (None, 1, 1, 128)         16512     
=================================================================
Total params: 562,496
Trainable params: 562,496
Non-trainable params: 0
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.