The parameter difference is from the Dense layers at the end, not the convolutional layers.
If you use nothing but convolutional layers with a global average layer at the end, you actually don’t have to specify image size at all.
Keras allows spatial dimensions to be None
, but as far as I know this will only work if images in each batch are all the same size. So you could either bin your images or use batch size 1.
FYI this is just a simple example network, unlikely to be useful. Also I’m using TF dim ordering, not TH, i.e. channels as last axis
from keras.models import Model
from keras.layers import Input, Conv2D, GlobalAveragePooling2D
img_input = Input(shape=(None, None, 3))
x = Conv2D(32, 3, 3, border_mode='same')(img_input)
x = MaxPooling2D((2,2))(x)
x = Conv2D(64, 3, 3, border_mode='same')(x)
x = MaxPooling2D((2,2))(x)
x = Conv2D(128, 3, 3, border_mode='same')(x)
output = GlobalAveragePooling2D()(x)
model = Model(input=img_input, output=output)
print(model.summary())
'''
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_12 (InputLayer) (None, None, None, 3) 0
____________________________________________________________________________________________________
convolution2d_17 (Convolution2D) (None, None, None, 32 896 input_12[0][0]
____________________________________________________________________________________________________
maxpooling2d_10 (MaxPooling2D) (None, None, None, 32 0 convolution2d_17[0][0]
____________________________________________________________________________________________________
convolution2d_18 (Convolution2D) (None, None, None, 64 18496 maxpooling2d_10[0][0]
____________________________________________________________________________________________________
maxpooling2d_11 (MaxPooling2D) (None, None, None, 64 0 convolution2d_18[0][0]
____________________________________________________________________________________________________
convolution2d_19 (Convolution2D) (None, None, None, 12 73856 maxpooling2d_11[0][0]
____________________________________________________________________________________________________
globalaveragepooling2d_1 (Global (None, 128) 0 convolution2d_19[0][0]
====================================================================================================
Total params: 93,248
Trainable params: 93,248
Non-trainable params: 0
'''
Output will be (None, 128) and it will accept images of any size.
N.B. You won’t be able to use the default keras image preprocessing objects unless you tweak them a bit.