I want to use the MobileNet model pre-trained on ImageNet for feature extraction. I am loading the model as follows:
from keras.applications.mobilenet import MobileNet
feature_model = MobileNet(include_top=False, weights='imagenet', input_shape=(200, 200, 3))
The Keras manual clearly says that this input shape is valid:
input_shape: optional shape tuple, only to be specified if include_top is False (otherwise the input shape has to be (224, 224, 3) (with 'channels_last' data format) or (3, 224, 224) (with 'channels_first' data format). It should have exactly 3 inputs channels, and width and height should be no smaller than 32. E.g. (200, 200, 3) would be one valid value.
However, I get the following error message:
ValueError: If imagenet weights are being loaded, input must have a static square shape (one of (128, 128), (160, 160), (192, 192), or (224, 224)). Input shape provided = (200, 200, 3)
Why does it require the input shape to match the one it was trained on if I specify include_top=False?
Keras: 2.2.4, TensorFlow: 1.13.1
Update: As @Soroush pointed out, this exception was removed recently. However, the issue was not fully resolved as described here.
Update2: The problem was resolved by these two pull requests (1, 2).
include_top=False, the model consists of convolutional layers only (no FC layers). Why is it then limited to these shapes? E.g. I can load the VGG16 model using an arbitrary input shape even though it was trained on ImageNet with the shape of (224,224,3) - Evgeny