tensorflow eager模块出错

时间:2017-11-07 08:40:30

标签: tensorflow

我的操作系统是Ubuntu 16.04

Python版本为3.5

Tensorflow版本为14.0

当我尝试使用TF Eager模块的简单代码时

import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
x = [[2.]]
m = tf.matmul(x, x)

我得到了

  

AttributeError:模块'tensorflow.contrib.eager'没有属性'enable_eager_execution'

那有什么不对?

3 个答案:

答案 0 :(得分:5)

来自渴望user guide

  

TensorFlow的最新版本(版本1.4)中未包含Eager执行。要使用它,您需要从源代码构建TensorFlow或安装每晚构建。

尝试安装Tensorflow的每晚版本而不是1.4.0。

答案 1 :(得分:0)

正如@Sunreef指出的那样,你应该安装tensorflow的夜间工件以便使用TensorFlow eager模式。这是一个新的实验性功能,尚未包含在发行版中。

要安装每晚pip包,请执行:

# For CPU only
pip install tf-nightly  
# For GPU support
pip install tf-nightly-gpu

还有夜间docker / nvidia-docker图像,提供Jupyter Notebook界面。

# If you have a GPU, use https://github.com/NVIDIA/nvidia-docker
nvidia-docker pull tensorflow/tensorflow:nightly-gpu
nvidia-docker run -it -p 8888:8888 tensorflow/tensorflow:nightly-gpu

# If you do not have a GPU, use the CPU-only image
docker pull tensorflow/tensorflow:nightly
docker run -it -p 8888:8888 tensorflow/tensorflow:nightly

有关详细信息,请参阅this page

答案 2 :(得分:0)

从版本1.8开始,急速执行模式已添加到Tensorflow。因此,有必要进行更新。此外,它是一个相对较新的功能,具有许多故障并经常更新,因此建议使用可以为您服务的最新版本。 试试

conda update tensorflow

或带有点子

pip install --upgrade Tensorflow