udacity / dlnd-issue-reports

5 stars 0 forks source link

Error while fetching MNIST data #80

Closed kulshekhar closed 7 years ago

kulshekhar commented 7 years ago

In the exercise on handwritten digit recognition (in the 'Intro to TFLearn' lesson), I'm getting the following error when trying to execute the code that loads the MNIST data:

Extracting mnist/train-images-idx3-ubyte.gz
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-bb487e4cbb6a> in <module>()
      1 # Retrieve the training and test data
----> 2 trainX, trainY, testX, testY = mnist.load_data(one_hot=True)

/home/user/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tflearn/datasets/mnist.py in load_data(one_hot)
     13 
     14 def load_data(one_hot=False):
---> 15     mnist = read_data_sets("mnist/", one_hot=one_hot)
     16     return mnist.train.images, mnist.train.labels, mnist.test.images, mnist.test.labels
     17 

/home/user/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tflearn/datasets/mnist.py in read_data_sets(train_dir, fake_data, one_hot)
    159     VALIDATION_SIZE = 5000
    160     local_file = maybe_download(TRAIN_IMAGES, train_dir)
--> 161     train_images = extract_images(local_file)
    162     local_file = maybe_download(TRAIN_LABELS, train_dir)
    163     train_labels = extract_labels(local_file, one_hot=one_hot)

/home/user/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tflearn/datasets/mnist.py in extract_images(filename)
     48         rows = _read32(bytestream)
     49         cols = _read32(bytestream)
---> 50         buf = bytestream.read(rows * cols * num_images)
     51         data = numpy.frombuffer(buf, dtype=numpy.uint8)
     52         data = data.reshape(num_images, rows, cols, 1)

/home/user/anaconda3/envs/tensorflow/lib/python3.5/gzip.py in read(self, size)
    272             import errno
    273             raise OSError(errno.EBADF, "read() on write-only GzipFile object")
--> 274         return self._buffer.read(size)
    275 
    276     def read1(self, size=-1):

TypeError: only integer scalar arrays can be converted to a scalar index

I get this error when executing the code from the notebook and also while executing it in the REPL.

I spent some time on this but was unable to figure out what I could do to fix this. Any pointers would be very helpful.

Edit: System details: Linux Mint 18 (~ Ubuntu 16.04) Python 3.5 via Anaconda Haven't faced any issues in any other tasks/exercises in the course so far

kulshekhar commented 7 years ago

Update: I've tried updating anaconda & all the installed packages but I haven't been able to figure out a way to fix this.

Searching for this error, I also came across this stackoverflow question which looks similar but I wasn't able to use the answer to fix this issue

kulshekhar commented 7 years ago

Update: Fixed

For posterity:

This issue is similar to the one posted on this stackoverflow question. The solution was similar. In this case, update the _read32 function in tflearn/dataset/mnist.py from

def _read32(bytestream):
    dt = numpy.dtype(numpy.uint32).newbyteorder('>')
    return numpy.frombuffer(bytestream.read(4), dtype=dt)

to

def _read32(bytestream):
    dt = numpy.dtype(numpy.uint32).newbyteorder('>')
    return numpy.frombuffer(bytestream.read(4), dtype=dt)[0]

I see that the latest source code of tflearn has this fixed. For some reason, installing TFLearn by following the instructions in the lesson wasn't sufficient to avoid this issue.

arthurtsang commented 7 years ago

thanks, that's very helpful. i get the latest by pip install git+https://github.com/tflearn/tflearn.git