Python 导入 input_data MNIST 张量流不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33664651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import input_data MNIST tensorflow not working
提问by O.rka
TensorFlow MNIST example not running with fully_connected_feed.py
TensorFlow MNIST 示例未与fully_connected_feed.py 一起运行
I checked this out and realized that input_data
was not built-in. So I downloaded the whole folder from here. How can I start the tutorial:
我检查了这个并意识到它input_data
不是内置的。所以我从这里下载了整个文件夹。如何开始本教程:
import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-a5af65173c89> in <module>()
----> 1 import input_data
2 mnist = tf.input_data.read_data_sets("MNIST_data/", one_hot=True)
ImportError: No module named input_data
I'm using iPython (Jupyter) so do I need to change my working directory to this folder I downloaded? or can I add this to my tensorflow
directory? If so, where do I add the files? I installed tensorflow
with pip
(on my OSX) and the current location is ~/anaconda/lib/python2.7/site-packages/tensorflow/__init__.py
我正在使用 iPython (Jupyter),所以我需要将我的工作目录更改为我下载的这个文件夹吗?或者我可以将它添加到我的tensorflow
目录中吗?如果是这样,我在哪里添加文件?我安装tensorflow
了pip
(在我的 OSX 上),当前位置是~/anaconda/lib/python2.7/site-packages/tensorflow/__init__.py
Are these files meant to be accessed directly through tensorflow
like sklearn
datasets? or am I just supposed to cd into the directory and work from there? The example is not clear.
这些文件是要通过tensorflow
类似的sklearn
数据集直接访问吗?还是我只是应该 cd 进入目录并从那里开始工作?例子不清楚。
采纳答案by Salvador Dali
So let's assume that you are in the directory: /somePath/tensorflow/tutorial
(and this is your working directory).
因此,让我们假设您在目录中:(/somePath/tensorflow/tutorial
这是您的工作目录)。
All you need to do is to download the input_data.pyand put it this. Let the file name where you invoke:
您需要做的就是下载input_data.py并将其放入。让您调用的文件名:
import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
...
is main.py
and it is also in this directory.
是main.py
,它也在这个目录中。
Whenever this is done, you can just start running main.py
which will start downloading the files and will put them in the MNIST_data folder (once they are there the script will not be downloading them next time).
每当这完成后,您就可以开始运行main.py
,这将开始下载文件并将它们放在 MNIST_data 文件夹中(一旦它们在那里,脚本下次将不会下载它们)。
回答by Will From Tokyo
I am using different version - following Install on Windows with Docker here- and had similar problem.
我使用不同的版本-继在Windows上安装泊坞这里-并有类似的问题。
An easy workaround I've found was:
我发现的一个简单的解决方法是:
1.Into the Linux command line, figure out where is the input_data.py on my Docker image (in your case you mentionned that you had to download it manually. In my case, it was already here). I used the follwing linux command:
1.进入Linux命令行,找出我的Docker镜像上的input_data.py在哪里(在你的情况下你提到你必须手动下载它。在我的情况下,它已经在这里)。我使用了以下 linux 命令:
$ sudo find . -print | grep -i '.*[.]py'
I've got the files & path
我有文件和路径
./tensorflow/g3doc/tutorials/mnist/mnist.py
./tensorflow/g3doc/tutorials/mnist/input_data.py
2.launch Python and type the following command using SYS:
2. 启动 Python 并使用 SYS 键入以下命令:
>> import sys
>> print(sys.path)
you will get the existing paths.
您将获得现有路径。
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
4.add the path of inputa_data.py:
4.添加inputa_data.py的路径:
>> sys.path.insert(1,'/tensorflow/tensorflow/g3doc/tutorials/mnist')
Hope that it can help. If you found better option, let me know. :)
希望它能有所帮助。如果您找到更好的选择,请告诉我。:)
回答by masaya
How can I start the tutorial
我如何开始教程
I didn't download the folder you did but I installed tensorflow by pip and then I had similar problem.
我没有下载你做的文件夹,但我通过 pip 安装了 tensorflow,然后我遇到了类似的问题。
My workaround was to replace
我的解决方法是更换
import tensorflow.examples.tutorials.mnist.input_data
import tensorflow.examples.tutorials.mnist.input_data
with
和
import tensorflow.examples.tutorials.mnist.input_data as input_data
import tensorflow.examples.tutorials.mnist.input_data as input_data
回答by Kongsea
The old tutorial said, to import the MNIST data, use:
老教程说,要导入MNIST数据,使用:
import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
This will cause the error. The new tutorial uses the following code to do so:
这将导致错误。新教程使用以下代码来执行此操作:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data", one_hot=True)
And this works well.
这很有效。
回答by John
I might be kinda late, but for tensorflow version 0.12.1, you might wanna use input_data.read_data_sets instead.
我可能有点晚了,但是对于 tensorflow 0.12.1 版,您可能想改用 input_data.read_data_sets。
Basically using this function to load the data from your local drive that you had downloaded from http://yann.lecun.com/exdb/mnist/.
基本上使用此功能从您从http://yann.lecun.com/exdb/mnist/下载的本地驱动器加载数据。
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('data_set/')
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('data_set/')
回答by m0z4rt
cd your_mnist_dir &&\
wget https://github.com/HIPS/hypergrad/raw/master/data/mnist/mnist_data.pkl &&\
wget https://github.com/HIPS/hypergrad/raw/master/data/mnist/t10k-images-idx3-ubyte.gz &&\
wget https://github.com/HIPS/hypergrad/raw/master/data/mnist/t10k-labels-idx1-ubyte.gz &&\
wget https://github.com/HIPS/hypergrad/raw/master/data/mnist/train-images-idx3-ubyte.gz &&\
wget https://github.com/HIPS/hypergrad/raw/master/data/mnist/train-labels-idx1-ubyte.gz
回答by Cro
MNIST input_data was built-in, it's just not a individual module, it's inside Tensorflow module, try
MNIST input_data 是内置的,它不是一个单独的模块,它在 Tensorflow 模块内部,试试
from tensorflow.examples.tutorials.mnist import input_data
回答by jitsm555
MNIST data set included as a part of tensorflow examples tutorial, If we want to use this :
MNIST 数据集包含在 tensorflow 示例教程中,如果我们想使用它:
Import MNIST data to identify handwritten digites
导入 MNIST 数据以识别手写数字
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST data", one_hot=True)
回答by Victor John
As TensorFlow official website shown, All MNIST data is hosted on http://yann.lecun.com/exdb/mnist/
正如 TensorFlow 官网所示,所有 MNIST 数据都托管在http://yann.lecun.com/exdb/mnist/
回答by Vasco Cansado Carvalho
For TensorFlow API 2.0the mnist data changed place to: tf.keras.datasets.mnist.load_data
对于TensorFlow API 2.0,mnist 数据的位置更改为:tf.keras.datasets.mnist.load_data