cant load mnist dataset in keras

2019-08-07 19:12发布

问题:

im trying to load the mnist dataset by :

import keras
from keras.datasets import mnist
(x_train,y_train),(x_test,y_test)=mnist.load_data()

but i get this error :

  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\anaconda\lib\site-packages\keras\datasets\mnist.py", line 15, in load_data
  data = cPickle.load(f)
  File "E:\anaconda\lib\gzip.py", line 252, in read
  raise IOError(errno.EBADF, "read() on write-only GzipFile object")
  IOError: [Errno 9] read() on write-only GzipFile object

what should i do?

thanks

回答1:

MNIST database of handwritten digits

Dataset of 60,000 28x28 grayscale images of the 10 digits, along with a test set of 10,000 images.

Usage:

  from keras.datasets import mnist

  (x_train, y_train), (x_test, y_test) = mnist.load_data()

Returns:

2 tuples: x_train, x_test: uint8 array of grayscale image data with shape (num_samples, 28, 28).

y_train, y_test: uint8 array of digit labels (integers in range 0-9) with shape (num_samples,). Arguments:

Note(path: if you do not have the index file locally (at '~/.keras/datasets/' + path), it will be downloaded to this location.)