配置Keras以使用Tensorflow而不是Theano [英] Configuring Keras to use Tensorflow instead of Theano

查看:88
本文介绍了配置Keras以使用Tensorflow而不是Theano的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Anaconda virtualenv下配置Keras安装,并在Ubuntu 17.04下运行所有​​安装.我已经通过conda安装了keras-gpu,并通过运行python -c 'import keras'生成了一个引导~/.keras目录;最后,我已经在该目录中更新了keras.json,将tensorflow作为后端而不是theano.

I'm trying to configure Keras install under an Anaconda virtualenv with all of that running under Ubuntu 17.04. I've installed keras-gpu via conda, and have generated a bootstrap ~/.keras directory by running python -c 'import keras'; finally, I've updated my keras.json within that directory to include tensorflow as the backend rather than theano.

我还尝试使用conda上可用的常规非GPU keras进行这些步骤.

I've also tried those steps with the regular, non-GPU keras available on conda.

我遇到的问题是,我的keras.json中的backend选项正在读取(因为无效值引发异常),但是被Anaconda本身获取export的环境变量所取代- -根据grep,有以下几种情况:

The issue I'm getting is that the backend option in my keras.json is being read (since invalid values raise exceptions), but is being overruled by an environment variable that gets exported by Anaconda itself -- according to grep, there are a few instances of:

export KERAS_BACKEND=tensorflow
export KERAS_BACKEND=theano

...散布在~/miniconda3/pkgs/keras-2.0.2-py36_1/中的许多文件中.

... Scattered around a number of files in ~/miniconda3/pkgs/keras-2.0.2-py36_1/.

由于文件包管理器会自动将这些文件放到这里,因此我不愿意手动编辑这些文件,但我也想避免在每个会话开始时明确指定KERAS_BACKEND=tensorflow,并且我想避免使用解决方案涉及到direnv之类的工具.

I'm hesitant to manually edit these files since they're automatically put there by the package manager, but I also want to avoid explicitly specifying KERAS_BACKEND=tensorflow at the start of each session, and I'd like to avoid solutions involving tools like direnv.

如何让condakeras默认使用tensorflow?

推荐答案

问题可能出在

The problem is probably in the file activate.sh of the keras package on conda-forge. The export statements in this file are unnecessary and should be removed IMO. There's just no reason to restrict linux users to use theano as Keras backend (or TensorFlow for Mac OSX).

#!/bin/bash
if [ "$(uname)" == "Darwin" ]
then
    # for Mac OSX
    export KERAS_BACKEND=tensorflow
elif [ "$(uname)" == "Linux" ]
then
    # for Linux
    export KERAS_BACKEND=theano
fi

您可以通过以下方法解决问题:

You could solve the problem by:

  1. 从activate.sh中删除这些环境设置.
  2. 删除当前安装的keraskeras-gpu,然后 用conda install -c defaults keras安装keras: 非conda-forge版本的keras似乎还可以.我的机器上没有找到任何这些环境设置.
  3. pip install keras:删除当前安装的keraskeras-gpu,然后仅安装python软件包.
  1. Removing those environment settings from activate.sh.
  2. Removing currently installed keras and keras-gpu, and then install keras with conda install -c defaults keras: the non-conda-forge version of keras seems to be okay. I didn't find any of those env settings on my machine.
  3. pip install keras: removing currently installed keras and keras-gpu, and then install the python package only.

这篇关于配置Keras以使用Tensorflow而不是Theano的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆