import input_data MNIST tensorflow not working

2020-02-09 05:54发布

TensorFlow MNIST example not running with 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:

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

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.

11条回答
▲ chillily
2楼-- · 2020-02-09 06:25

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.

查看更多
做个烂人
3楼-- · 2020-02-09 06:25
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
查看更多
男人必须洒脱
4楼-- · 2020-02-09 06:25

For TensorFlow API 2.0 the mnist data changed place to: tf.keras.datasets.mnist.load_data

查看更多
▲ chillily
5楼-- · 2020-02-09 06:29

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/')

查看更多
混吃等死
6楼-- · 2020-02-09 06:31

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

查看更多
神经病院院长
7楼-- · 2020-02-09 06:33

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

查看更多
登录 后发表回答