简体   繁体   English

无法从 keras.utils 导入 multi_gpu_model

[英]Cannot import multi_gpu_model from keras.utils

I have tensorflow-gpu 1.2.1 and keras on ubuntu 16.04.我在 ubuntu 16.04 上有 tensorflow-gpu 1.2.1 和 keras。

I am not able to perform:我无法执行:

from kears.utils import multi_gpu_model 

Has anyone had success with multi_gpu_model as described in their documentation's FAQ section?有没有人按照文档的常见问题部分中的描述在 multi_gpu_model 上取得成功?

I have a 4 GPU machine with 4 GeForce GTX 1080 Ti cards and want to use all of them.我有一台带有 4 个 GeForce GTX 1080 Ti 卡的 4 GPU 机器,我想使用所有这些卡。

Here's the error I get:这是我得到的错误:

import keras.utils.multi_gpu_model

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-7-0174878249b1> in <module>()
----> 1 import keras.utils.multi_gpu_model
      2 

ModuleNotFoundError: No module named 'keras.utils.multi_gpu_model'

I can import keras and keras.utils successfully.我可以成功导入 keras 和 keras.utils。

pip uninstall keras 
pip install keras==2.2.4

this helped me ... working on keras hrnetv2这对我有帮助......在 keras hrnetv2 上工作

This function was added on October 11, and there have been no Keras releases that include it.这个功能是在 10 月 11 日添加的,目前还没有包含它的 Keras 版本。 Currently the last Keras release is 2.0.8 released on Aug 25, 2017.目前最新的 Keras 版本是 2017 年 8 月 25 日发布的 2.0.8。

Your only options are to wait until a release is made, or to use a Keras version directly from git master.您唯一的选择是等待发布,或者直接从 git master 使用 Keras 版本。

Except Matias comment, you could also 除了Matias评论,您还可以

copy the multi_gpu_model code from https://github.com/fchollet/keras/blob/master/keras/utils/training_utils.py https://github.com/fchollet/keras/blob/master/keras/utils/training_utils.py复制multi_gpu_model代码

要解决此问题:我从 github 安装了最新版本的 Keras,并让 multi_gpu_model 模块按预期工作。

pip install git+git://github.com/fchollet/keras.git --upgrade

对于 Tensorflow 2.7.0,这有效:

from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model

You could reinstall tensorflow-estimator and keras like this:您可以像这样重新安装 tensorflow-estimator 和 keras:

pip uninstall tensorflow-estimator
pip install tensorflow-estimator
pip uninstall keras
pip install keras

I was able to resolve the issue by this.我能够通过这个解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM