keras-vggface icon indicating copy to clipboard operation
keras-vggface copied to clipboard

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

Open jkortner opened this issue 3 years ago • 5 comments

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'

jkortner avatar Aug 20 '21 13:08 jkortner

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

arnoldcvl avatar Aug 25 '21 19:08 arnoldcvl

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.

vmarichkav avatar Aug 28 '21 13:08 vmarichkav

Same issue here, can this fix be merged?

tamis-laan avatar Dec 20 '21 16:12 tamis-laan

Same issue here, can this fix be merged?

inhyeokJeon avatar Feb 25 '22 11:02 inhyeokJeon

Same issue here, can this fix be merged?

braludo avatar Mar 31 '22 12:03 braludo

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

Keven1894 avatar Dec 25 '22 04:12 Keven1894

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.

nidham-sony avatar Jan 03 '23 19:01 nidham-sony

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)

PierrunoYT avatar Feb 26 '23 20:02 PierrunoYT

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.

sbelharbi avatar Mar 15 '23 21:03 sbelharbi

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 avatar Jun 01 '23 18:06 bibinkunjumon2020

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

bibinkunjumon2020 avatar Jun 10 '23 19:06 bibinkunjumon2020