ModuleNotFoundError: No module named 'keras.engine.topology'
jkortner opened this issue ยท 11 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'
Same error for me when using the latest keras version. Keras 2.4.3/tensorflow 2.5 works fine.
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 issue here, can this fix be merged?
Same issue here, can this fix be merged?
Same issue here, can this fix be merged?
I solved this issue by changing the import from
from keras.engine.topology import get_source_inputs
tofrom keras.utils.layer_utils import get_source_inputs
inkeras_vggface/models.py
.I made a PR for this issue.
same problem solved by this, plz accept the PR
I solved this issue by changing the import from
from keras.engine.topology import get_source_inputs
tofrom keras.utils.layer_utils import get_source_inputs
inkeras_vggface/models.py
.I made a PR for this issue.
Same thing, it worked here.
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)
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
tofrom keras.utils.layer_utils import get_source_inputs
inkeras_vggface/models.py
.I made a PR for this issue.
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
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