Lasagne/Recipes

InputLayer size in the models googlenet, vgg16, vgg19, vgg_cnn_s

Closed this issue · 1 comments

I looked at four models of Recipes/modelzoo/
it's googlenet.py, vgg16.py, vgg19.py, vgg_cnn_s.py
For models of vgg16.py, vgg19.py, vgg_cnn_s.py the input layer is set so InputLayer((None, 3, 224, 224)) those the input image has a size 224_224. Is it correctly if to load models such as (vgg16, vgg19) but change the input layer i.e. for classification and retraining the images will be a other size(128_128 or other).
Model googlenet in the input layer set without dimensions InputLayer((None, 3, None, None))
This means that the input image can be any size?

f0k commented

Please have a look at the last part of the model, i.e., the part leading to the classifier. For the VGG-nets, it directly goes from convolution/pooling layers to dense layers, and the first dense layer expects a particular incoming shape that you only receive for input images of 224x224 (and maybe some pixels more or less, if they result in feature maps of the same size later on due to pooling or strides).
In contrast, GoogLeNet has a global average pooling later before the dense layer, so whatever the input image size, the dense layer will see the same incoming shape. That's why it also works for images of a different size.
So to adapt VGG networks to a different size, it's not enough to only change the input layer definition, you also need new weights for the first dense layer (since the weight matrix will need to have a different shape).