Change default size to allow different MobileNet sizes #7586
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@fchollet There is a MobileNet image size selection problem in the current implementation.
Due to the use of
_obtain_input_shape(...)
, the default_size provided is a static 224. While this generally works well for models with only 1 input size, for the MobileNet family of models, it is not suitable.The issue is that when one passes
input_shape
as anything other than the default of 224 (128, 160 and 192 are supported as well), an error stating that the default size required withinclude_top=True
is (224, 224, 3) is raised. This is a problem, since there exist weights for smaller input size models. They just can't be accessed with the standard working of_obtain_input_shape
.There are two possible ways to fix this :
Make
_obtain_input_shape
support a list of default sizes. Usage of this method would be simpler then, though a very clean implementation would be a tad bit more difficult (but can be managed).Do a pre-check for
input_shape
(if provided), check it is one of the possible sizes supported by MobileNet, and then change thedefault_size
to match this input size. There is a fallback to thedefault_size
= 224 if the provided input shape is not in the list of supported sizes (and then_obtain_input_shape
can check and raise errors if needed).This means there is no need to change the
_obtain_input_shape
code, and the task falls to the method caller to make sure the correctdefault_size
is provided.In my opinion, since it is relatively rare for a single model to be trained on different image sizes, I prefer option 2. Therefore, that has been implemented in this PR.