ufldl_tutorial icon indicating copy to clipboard operation
ufldl_tutorial copied to clipboard

ValueError

Open mengxue-rs opened this issue 7 years ago • 1 comments

when I run the train.py,I get the following error images = images.reshape((num_images[0], num_rows[0] * num_cols[0])).transpose() Traceback (most recent call last): File "/home/snow/Documents/study/ufldl_tutorial/train.py", line 42, in images = load_MNIST.load_MNIST_images('data/mnist/train-images-idx3-ubyte') File "/home/snow/Documents/study/ufldl_tutorial/load_MNIST.py", line 20, in load_MNIST_images images = images.reshape((num_images[0], num_rows[0] * num_cols[0])).transpose() ValueError: cannot reshape array of size 9912406 into shape (2055376946,1902539786)

#####code begin with open(filename, "rb") as f: magic = np.fromfile(f, dtype=np.dtype('>i4'), count=1)

    num_images = np.fromfile(f, dtype=np.dtype('>i4'), count=1)
    num_rows = np.fromfile(f, dtype=np.dtype('>i4'), count=1)
    num_cols = np.fromfile(f, dtype=np.dtype('>i4'), count=1)
    #num_images = 60000
    #num_rows = 28
    #num_cols = 28
    images = np.fromfile(f, dtype=np.ubyte)
    images = images.reshape((num_images[0], num_rows[0] * num_cols[0])).transpose()
    images = images.astype(np.float64) / 255

    f.close()

#####code end

I google the http://yann.lecun.com/exdb/mnist/ find the value: 0004 32 bit integer 60000 number of images 0008 32 bit integer 28 number of rows 0012 32 bit integer 28 number of columns

by calculating the value, I find 282860000 larger than the 9912422,that makes me so confused, How can I correct the code?

mengxue-rs avatar Oct 19 '17 14:10 mengxue-rs

It's easy to solve, when you download these file(.gz), you must decompressed they at first. I meet the error, for these words in the http://yann.lecun.com/exdb/mnist/

please note that your browser may uncompress these files without telling you. If the files you downloaded have a larger size than the above, they have been uncompressed by your browser. Simply rename them to remove the .gz extension.

mengxue-rs avatar Oct 24 '17 08:10 mengxue-rs