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

19.5k Views Asked by At

There are several tutorials online that import a VGGFace model from keras_vggface like this:

from keras_vggface.vggface import VGGFace

However, I get the following error:

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

This problem happens on my local machine, but also on Google Colab after installing keras_vggface with

!pip install keras_vggface
3

There are 3 best solutions below

1
Prophet On

I think you need to install it as below:

!pip install keras_vggface

It should work

2
mariia_vasyleha On

I solved this issue in Google Colab by changing the import from

from keras.engine.topology import get_source_inputs

to

from keras.utils.layer_utils import get_source_inputs

in usr/local/lib/python3.7/dist-packages/keras_vggface/models.py

0
alex smolyakov On
! pip install git+https://github.com/rcmalli/keras-vggface.git
!pip install keras_applications --no-deps
filename = "/usr/local/lib/python3.7/dist-packages/keras_vggface/models.py"
text = open(filename).read()
open(filename, "w+").write(text.replace('keras.engine.topology', 'tensorflow.keras.utils'))
import tensorflow as tf

from keras_vggface.vggface import VGGFace

vggface = VGGFace(model='resnet50') # or VGGFace() as default

worked for me and colab