Sam Geisler
Sam Geisler

Reputation: 15

'Magic number mismatch' error when loading mnist dataset

I'm trying to load the mnist digit dataset and am routinely getting this error. I'm unable to find any solutions online

This code:

from mnist import MNIST
m = MNIST(path)
x_train, y_train = m.load_training()

Yields this error:

File "<stdin>", line 1, in <module>
  File "C:\Python38\lib\site-packages\mnist\loader.py", line 125, in load_training
    ims, labels = self.load(os.path.join(self.path, self.train_img_fname),
  File "C:\Python38\lib\site-packages\mnist\loader.py", line 250, in load
    raise ValueError('Magic number mismatch, expected 2049,'
ValueError: Magic number mismatch, expected 2049,got 529205256

I'm running python-mnist 0.7.

Upvotes: 1

Views: 1123

Answers (1)

Platt
Platt

Reputation: 19

I've just had the exact same error and I fixed it by renaming the files:

  • First you download the data as gzip files. The should look like this: "train-labels-idx1-ubytes.gz"
  • then you need to extract these files
  • then you probably get files similar to this one: "train-labels.idx1-ubyte". The error with this is that the file should be named like "train-labels-idx1-ubyte" (hyphen instead of dot).

If you rename the files like that it should work, at least that's what worked for me.

Upvotes: 1

Related Questions