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条回答
做个烂人
2楼-- · 2020-02-09 06:34

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

enter image description here

查看更多
相关推荐>>
3楼-- · 2020-02-09 06:34

There's now a much easier way to load MNIST data into tensorflow without having to download the data by using Tensorflow 2 and Tensorflow Datasets

To get started, make sure you import Tensorflow and specify the 2nd version:

%tensorflow_version 2.x
import tensorflow as tf

Then load the data into a dictionary using the following code:

MNIST_data = tfds.load(name = "mnist")

and Then split the data into train and test:

train, test = MNIST_data['train'] , MNIST_data['test']

Now you can use these data generators however you like.

查看更多
▲ chillily
4楼-- · 2020-02-09 06:37

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

查看更多
相关推荐>>
5楼-- · 2020-02-09 06:40

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
查看更多
Ridiculous、
6楼-- · 2020-02-09 06:40

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)
查看更多
登录 后发表回答