简体   繁体   English

如何在 gpu 支持下安装 Keras?

[英]How to install Keras with gpu support?

我使用以下命令为 GPU 安装了 Tensorflow: pip install tensorflow-gpu但是当我为Keras pip install keras-gpu尝试相同的方法时,它给我带来了一个错误:找不到满足要求的版本

Adding to the answer above which is the correct answer in terms of recommending to use Anaconda package manager, but out of date in that there is now a keras-gpu package on Anaconda Cloud .添加到上面的答案中,这是推荐使用 Anaconda 包管理器的正确答案,但已过时,因为现在Anaconda Cloud一个keras-gpu包。

So once you have Anaconda installed, you simply need to create a new environment where you want to install keras-gpu and execute the command:所以一旦你安装了 Anaconda,你只需要创建一个新的环境来安装 keras-gpu 并执行命令:

conda install -c anaconda keras-gpu

This will install Keras along with both tensorflow and tensorflow-gpu libraries as the backend.这将安装 Keras 以及作为后端的 tensorflow 和 tensorflow-gpu 库。 (There is also no need to install separately the CUDA runtime and cudnn libraries as they are also included in the package - tested on Windows 10 and working). (也不需要单独安装 CUDA 运行时和 cudnn 库,因为它们也包含在包中 - 在 Windows 10 上测试并正常工作)。

There is not any keras-gpu package [ UPDATE : now there is, see other answer below];没有任何keras-gpu包 [更新现在有,请参阅下面的其他答案]; Keras is a wrapper around some backends, including Tensorflow, and these backends may come in different versions, such as tensorflow and tensorflow-gpu . Keras 是一些后端的包装器,包括 Tensorflow,这些后端可能有不同的版本,例如tensorflowtensorflow-gpu But this does not hold for Keras itself, which should be installed simply with但这不适用于 Keras 本身,它应该简单地安装

pip install keras

independently of whatever backend is used (see the PyPi docs ).独立于使用的任何后端(请参阅PyPi 文档)。

Additionally, and since you have tagged the question as anaconda , too, be informed that it is generally not advisable to mix your package managers (ie pip with conda ), and you may be better off installing Keras from the Anaconda cloud with此外,由于您也将问题标记为anaconda ,因此请注意通常不建议将您的包管理器(即pipconda )混合使用,并且您最好从Anaconda 云安装 Keras

conda install -c conda-forge keras 

Finally, you may be also interested to know that recent versions of Tensorflow include Keras as a subpackage, so you can use it without any additional installation;最后,您可能还想知道,最新版本的 Tensorflow 将 Keras 作为子包包含在内,因此您无需任何额外安装即可使用; see https://www.tensorflow.org/guide/kerashttps://www.tensorflow.org/guide/keras

For installing tensorflow-gpu from Anaconda cloud , you should use要从Anaconda cloud安装tensorflow-gpu ,您应该使用

conda install -c anaconda tensorflow-gpu 

before installing Keras.在安装 Keras 之前。 Be sure you do it in a different virtual environment, or after having uninstalled other versions (ie pip -installed ones), as there have been reported problems otherwise.确保您在不同的虚拟环境中执行此操作,或者在卸载其他版本(即pip安装的版本)之后执行此操作,因为否则会报告问题

Adding to the above two answers, ensure your TensorFlow/Keras environment is using Python 3.6.除了以上两个答案,请确保您的 TensorFlow/Keras 环境使用 Python 3.6。 Keras/TensorFlow doesn't work very well with Python 3.7, as of May 10, 2019.截至 2019 年 5 月 10 日,Keras/TensorFlow 不能很好地与 Python 3.7 配合使用。

I tried to use Keras/TensorFlow with Python 3.7 and I ended up having to reinstall Anaconda, since it sort of broke my Anaconda Prompt.我尝试在 Python 3.7 中使用 Keras/TensorFlow,但最终不得不重新安装 Anaconda,因为它有点破坏了我的 Anaconda Prompt。

To install tensorflow-gpu with particular cuda version 9.0, use:要使用特定的 cuda 9.0 版安装 tensorflow-gpu,请使用:

"conda install tensorflow-gpu cudatoolkit==9.0 -c anaconda" “conda 安装 tensorflow-gpu cudatoolkit==9.0 -c anaconda”

Similarly for keras-gpu同样对于 keras-gpu

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

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