1

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
jkortner
  • 549
  • 2
  • 8
  • 23

3 Answers3

8

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

6
! 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

alex smolyakov
  • 198
  • 2
  • 8
0

I think you need to install it as below:

!pip install keras_vggface

It should work

Prophet
  • 32,350
  • 22
  • 54
  • 79