安装TensorFlow在EC2实例

问题描述:

我目前在Amazon EC2实例上运行,我试图运行在一个Jupyter笔记本电脑下面的代码(Python 2.7版)的例子:安装TensorFlow在EC2实例

from tensorflow.examples.tutorials.mnist import input_data 
mnist = input_data.read_data_sets("MNIST_data/") 
images, labels = mnist.train.images, mnist.train.labels 
images = images.reshape((55000,28,28)) 
np.savez_compressed("MNIST_data/train", images=images, labels=labels) 

不过,我得到以下错误:

--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
<ipython-input-4-de596f1c663d> in <module>() 
     1 
----> 2 from tensorflow.examples.tutorials.mnist import input_data 
     3 mnist = input_data.read_data_sets("MNIST_data/") 
     4 images, labels = mnist.train.images, mnist.train.labels 
     5 images = images.reshape((55000,28,28)) 

ImportError: No module named tensorflow.examples.tutorials.mnist 

到目前为止,我还没有安装任何库来获得TensorFlow代码的工作(我不完全确定为什么我不需要安装任何东西)。我如何安装这个示例集?

嗯,下面,

from tensorflow.examples.tutorials.mnist import input_data 
mnist = input_data.read_data_sets("MNIST_data", one_hot=True) 

应该工作,我只是双重检查。也许你已经安装了一个非常古老的TensorFlow版本?您可以通过

import tensorflow as tf 
tf.__version__ 

检查版本我不记得从何时input_data加入tensorflow.examples.tutorials.mnist但它应该与任何TF 1.1工作,1.2

+0

嘿塞巴斯蒂安 - 感谢您的快速答复。运行版本检查将返回“没有名为Tensorflow的模块”错误。事实证明,我的Amazon实例预装了Theano,但不包含TensorFlow。你知道我会如何在我的实例中使用Python 2.7安装TensorFlow吗? – Parseltongue

+1

我通常从Ubuntu实例中使用自己的AMI,但我不知道它们是如何设置的。但是,如果你幸运的话,就可以像从命令行执行'pip install tensorflow-gpu'一样简单。或者,您可以尝试其他答案中提到的DL AMI。或者,如果您想自己在AWS上设置DL实例/ AMI,请参阅以下步骤:https://sebastianraschka.com/pdf/books/dlb/appendix_h_cloud-computing.pdf – Sebastian

我会建议使用AWS深度学习AMI附带TensorFlow(其他MachineLearning软件包)已安装。

The AMI Ids for the Deep Learning Amazon Linux AMI are the following:
us-east-1: ami-4b44745d
us-east-2: ami-305d7c55
us-west-2: ami-296e7850
eu-west-1: ami-d36386aa
ap-southeast-2: ami-52332031
ap-northeast-1: ami-b44050d3
ap-northeast-2: ami-1523fc7b

Release tags/Branches used for the DW Frameworks:
MXNet : v0.10.0 tag
TensorFlow : v1.1.0 tag
Theano : rel-0.8.2 tag
Caffe : rc5 tag
Caffe2: v0.7.0
Keras : 1.2.2 tag
CNTK : v2.0.rc1 tag
Torch : master branch

description更多地了解它