keras_vggface:没有名为“keras.engine.topology”的模块

问题描述 投票:0回答:4

网上有几个从 keras_vggface 导入 VGGFace 模型的教程,如下所示:

from keras_vggface.vggface import VGGFace

但是,我收到以下错误:

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

这个问题发生在我的本地机器上,而且在安装

keras_vggface

后也出现在 Google Colab 上
!pip install keras_vggface
python keras google-colaboratory keras-vggface
4个回答
8
投票

我通过更改导入方式在 Google Colab 中解决了这个问题

from keras.engine.topology import get_source_inputs

from keras.utils.layer_utils import get_source_inputs

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

为我和colab工作


0
投票

我认为你需要按如下方式安装它:

!pip install keras_vggface

应该有效


0
投票

这可能取决于我们使用的 Keras 版本。尝试使用以下版本。 pip install keras==2.1.6.

© www.soinside.com 2019 - 2024. All rights reserved.