jkortner
jkortner

Reputation: 631

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

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

Upvotes: 1

Views: 20375

Answers (3)

alex smolyakov
alex smolyakov

Reputation: 318

! 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

Upvotes: 6

mariia_vasyleha
mariia_vasyleha

Reputation: 81

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

Upvotes: 8

Prophet
Prophet

Reputation: 33361

I think you need to install it as below:

!pip install keras_vggface

It should work

Upvotes: 0

Related Questions