import input_data MNIST tensorflow not working

徘徊边缘 提交于 2019-11-29 01:05:23
Salvador Dali

So let's assume that you are in the directory: /somePath/tensorflow/tutorial (and this is your working directory).

All you need to do is to download the input_data.py and put it this. Let the file name where you invoke:

import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
...

is main.py and it is also in this directory.

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).

The old tutorial said, to import the MNIST data, use:

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.

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.

My workaround was to replace

import tensorflow.examples.tutorials.mnist.input_data

with

import tensorflow.examples.tutorials.mnist.input_data as input_data

I am using different version - following Install on Windows with Docker here - and had similar problem.

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:

$ 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:

>> 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:

>> sys.path.insert(1,'/tensorflow/tensorflow/g3doc/tutorials/mnist')

Hope that it can help. If you found better option, let me know. :)

I might be kinda late, but for tensorflow version 0.12.1, you might wanna use input_data.read_data_sets instead.

Basically using this function to load the data from your local drive that you had downloaded from http://yann.lecun.com/exdb/mnist/.

from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets('data_set/')

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
Cro

MNIST input_data was built-in, it's just not a individual module, it's inside Tensorflow module, try

from tensorflow.examples.tutorials.mnist import input_data

MNIST data set included as a part of tensorflow examples tutorial, If we want to use this :

Import MNIST data to identify handwritten digites

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

As TensorFlow official website shown, All MNIST data is hosted on http://yann.lecun.com/exdb/mnist/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!