Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError #7

Open
mengxue-rs opened this issue Oct 19, 2017 · 1 comment
Open

ValueError #7

mengxue-rs opened this issue Oct 19, 2017 · 1 comment

Comments

@mengxue-rs
Copy link

mengxue-rs commented Oct 19, 2017

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
Copy link
Author

mengxue-rs commented Oct 24, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant