Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'keras.engine.topology' #73

Closed
jkortner opened this issue Aug 20, 2021 · 11 comments · Fixed by #89
Closed

ModuleNotFoundError: No module named 'keras.engine.topology' #73

jkortner opened this issue Aug 20, 2021 · 11 comments · Fixed by #89

Comments

@jkortner
Copy link

When I try to import keras-vggface in Google Colab I get the error: No module named 'keras.engine.topology'. The same happens on my local machine.

First, I install keras-vggface:

!pip install keras_vggface
!pip install keras_applications

Then, I try to import:

from keras_vggface.vggface import VGGFace

The output is as follows:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-20-4dcc6ac1877c> in <module>()
----> 1 from keras_vggface.vggface import VGGFace
      2 print(keras_vggface.__version__)

2 frames
/usr/local/lib/python3.7/dist-packages/keras_vggface/__init__.py in <module>()
----> 1 from keras_vggface.vggface import VGGFace
      2 from keras_vggface.version import __version__

/usr/local/lib/python3.7/dist-packages/keras_vggface/vggface.py in <module>()
      7 '''
      8 from __future__ import print_function
----> 9 from keras_vggface.models import RESNET50, VGG16, SENET50
     10 
     11 

/usr/local/lib/python3.7/dist-packages/keras_vggface/models.py in <module>()
     18 from keras import backend as K
     19 from keras_vggface import utils
---> 20 from keras.engine.topology import get_source_inputs
     21 import warnings
     22 from keras.models import Model

ModuleNotFoundError: No module named 'keras.engine.topology'
@arnoldcvl
Copy link

arnoldcvl commented Aug 25, 2021

Same error for me when using the latest keras version. Keras 2.4.3/tensorflow 2.5 works fine.

@vmarichkav
Copy link

vmarichkav commented Aug 28, 2021

I solved this issue by changing the import from
from keras.engine.topology import get_source_inputs
to
from keras.utils.layer_utils import get_source_inputs in keras_vggface/models.py.

I made a PR for this issue.

@tamis-laan
Copy link

Same issue here, can this fix be merged?

2 similar comments
@inhyeokJeon
Copy link

Same issue here, can this fix be merged?

@braludo
Copy link

braludo commented Mar 31, 2022

Same issue here, can this fix be merged?

@Keven1894
Copy link

I solved this issue by changing the import from from keras.engine.topology import get_source_inputs to from keras.utils.layer_utils import get_source_inputs in keras_vggface/models.py.

I made a PR for this issue.

same problem solved by this, plz accept the PR

@nidham-sony
Copy link

I solved this issue by changing the import from from keras.engine.topology import get_source_inputs to from keras.utils.layer_utils import get_source_inputs in keras_vggface/models.py.

I made a PR for this issue.

Same thing, it worked here.

@PierrunoYT
Copy link

PierrunoYT commented Feb 26, 2023

import cv2
import numpy as np
from keras.models import load_model
from keras.preprocessing import image
from keras_vggface.utils import preprocess_input
from keras_vggface.vggface import VGGFace
from keras.engine.base_layer import Layer

def age_gender_prediction(image_path):
# load the image using OpenCV
img = cv2.imread(image_path)
# convert the image from BGR to RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# resize the image to (224, 224) to match the input size of the VGGFace model
img = cv2.resize(img, (224, 224))
# convert the image to an array of floating point values
x = image.img_to_array(img)
# preprocess the image using the preprocess_input function from keras_vggface
x = np.expand_dims(x, axis=0)
x = preprocess_input(x, version=2)
# load the VGGFace model
model = VGGFace(model='resnet50')
# use the model to predict the gender and age of the person in the image
y_pred = model.predict(x)
# extract the gender and age predictions from the output of the model
gender_pred = 'Male' if np.argmax(y_pred[0][0:2]) == 0 else 'Female'
age_pred = int(np.floor(np.clip(y_pred[1], 0, 100))[0][0])
# print the predicted gender and age
print('Predicted Gender:', gender_pred)
print('Predicted Age:', age_pred)

example usage

image_path = r'C:\Users\pierr\Dropbox\pierre.jpg'
age_gender_prediction(image_path)

@sbelharbi
Copy link

hi @rcmalli,
can you please merge this pr to avoid editing every install.
very much appreciated.
thanks

I solved this issue by changing the import from from keras.engine.topology import get_source_inputs to from keras.utils.layer_utils import get_source_inputs in keras_vggface/models.py.

I made a PR for this issue.

@bibinkunjumon2020
Copy link

Go inside the installed library and change that line there.
from keras_vggface.vggface import VGGFace
To
from keras.utils import get_source_inputs

ANy similar issues can be fixed like this.Even in colab

@bibinkunjumon2020
Copy link

from keras.engine.topology import get_source_inputs
from keras.utils.data_utils import get_file

from keras.utils import layer_utils

to

from keras.utils import get_source_inputs
from tensorflow.python.keras.utils.data_utils import get_file
from tensorflow.python.keras.utils import layer_utils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.