【问题标题】:Keras package installationKeras 包安装
【发布时间】:2017-12-14 10:33:14
【问题描述】:

我正在尝试安装 Keras 包以使用机器学习工具。 不幸的是,我无法这样做。我已经安装了theano。我在 python 3.5 的单独环境中安装了 tensorflow,但我正在尝试为此使用 python 2.7。是这个问题吗?

C:\Users\User>pip install tensorflow   
Collecting tensorflow   
  Could not find a version that satisfies the requirement tensorflow (from versions: )   
No matching distribution found for tensorflow   

C:\Users\User>pip install keras
Requirement already satisfied: keras in c:\users\user\anaconda2\lib\site-packages   
Requirement already satisfied: theano in c:\users\user\anaconda2\lib\site-packages (from keras)   
Requirement already satisfied: pyyaml in c:\users\user\anaconda2\lib\site-packages (from keras)   
Requirement already satisfied: six in c:\users\user\anaconda2\lib\site-packages (from keras)   
Requirement already satisfied: numpy>=1.9.1 in c:\users\user\anaconda2\lib\site-packages (from theano->keras)   
Requirement already satisfied: scipy>=0.14 in c:\users\user\anaconda2\lib\site-packages (from theano->keras)   

当我尝试导入 keras 时,我仍然遇到导入错误,说没有找到 tensorflow 后端

【问题讨论】:

  • 说已经安装了keras,那么实际问题是什么?
  • 你真的尝试过使用 Keras 吗?好像已经安装好了,用Theano con你的config文件
  • 是的,我无法导入 keras。说找不到支持的 tensorflow
  • 如果您尝试为 python 2 安装 keras + tensorflow,那么它将无法工作,因为 tensorflow 支持 python 3。所以,如果您使用的是 python 2,那么最好使用 Theano 作为后端。

标签: python machine-learning neural-network keras theano


【解决方案1】:

Tensorflow officially 仅支持 Windows 上的 Python 3.5.x。对于 python 2,您需要将后端切换到 Theano。您可以在C:\Users\username\.keras\keras.json 中将 Keras 后端更改为 Theano。另请查看this 文档。

如果您想在脚本中切换到另一个 keras 后端,您也可以使用以下代码:

import os
os.environ['KERAS_BACKEND'] = "theano" #or "tensorflow"
import keras

【讨论】:

    猜你喜欢
    • 2017-04-30
    • 2017-05-15
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 2019-07-27
    • 2019-09-10
    • 1970-01-01
    • 2017-01-29
    相关资源
    最近更新 更多