'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
Solution 1:[1]
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
Solution 2:[2]
! 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
Solution 3:[3]
I think you need to install it as below:
!pip install keras_vggface
It should work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mariia_vasyleha |
| Solution 2 | alex smolyakov |
| Solution 3 | Prophet |
