Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name '_obtain_input_shape' from keras

In Keras,

I'm trying to import _obtain_input_shape as follows:

from keras.applications.imagenet_utils import _obtain_input_shape

However, I get the following error:

ImportError: cannot import name '_obtain_input_shape'

The reason I'm trying to import _obtain_input_shape is so that I can determine the input shape(so as to load VGG-Face as follows :

I'm using it to determine the correct input shape of the input tensor as follow:

input_shape = _obtain_input_shape(input_shape,
                                  default_size=224,
                                  min_size=48,
                                  data_format=K.image_data_format(),
                                  require_flatten=include_top)`

Please assist? Thanks in advance.

like image 627
Tshilidzi Mudau Avatar asked Mar 05 '18 14:03

Tshilidzi Mudau


4 Answers

You don't have to downgrade Keras 2.2.2.

In Keras 2.2.2 there is no _obtain_input_shape method in the keras.applications.imagenet_utils module. You can find it under keras-applications with the modul name keras_applications (underscore).

So you don't have to downgrade your Keras to 2.2.0 just change:

from keras.applications.imagenet_utils import _obtain_input_shape

to

from keras_applications.imagenet_utils import _obtain_input_shape
like image 140
Geeocode Avatar answered Oct 26 '22 17:10

Geeocode


I have found a method that works well. You just use

from keras_applications.imagenet_utils import _obtain_input_shape 

Notice: It is keras_applications instead of keras.application.

like image 29
galoiszhang Avatar answered Oct 26 '22 16:10

galoiszhang


This issue occured because of the version of keras.

In my case, I was downgrade keras 2.2.2 to 2.2.0, and the problem was solved.

like image 7
user5803658 Avatar answered Oct 26 '22 16:10

user5803658


In Colab I solved it by importing Keras and installing :

import keras
!pip install keras_applications
from keras_applications.imagenet_utils import _obtain_input_shape
like image 2
Giorgio Malagutti Avatar answered Oct 26 '22 17:10

Giorgio Malagutti