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

pickle.load(mnist_pickle) returns UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128) #241

Open
GanGral opened this issue Aug 16, 2023 · 4 comments

Comments

@GanGral
Copy link

GanGral commented Aug 16, 2023

lessons\3-NeuralNetworks\03-Perceptron

running MNIST = pickle.load(mnist_pickle)

results in

5 with gzip.open('../03-Perceptron/mnist.pkl.gz', 'rb') as mnist_pickle:
6
----> 7 MNIST = pickle.load(mnist_pickle)
8

UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)


Workaround, which creates future problems:

MNIST = pickle.load(mnist_pickle, encoding="latin1") works well, however, the next step to plot the dataset would result in

**TypeError Traceback (most recent call last)
C:\Users\IGOR~1.KOR\AppData\Local\Temp/ipykernel_32352/2720090614.py in
----> 1 print(MNIST['Train']['Features'][0][130:180])
2 print(MNIST['Train']['Labels'][0])
3 features = MNIST['Train']['Features'].astype(np.float32) / 256.0
4 labels = MNIST['Train']['Labels']
5 fig = pylab.figure(figsize=(10,5))

TypeError: tuple indices must be integers or slices, not str**

@GanGral
Copy link
Author

GanGral commented Aug 16, 2023

additional info:

mnist.pkl.gz is not available in the original location, so I downloaded it from
https://github.com/mnielsen/neural-networks-and-deep-learning/blob/master/data/mnist.pkl.gz

I assume the data is structured differently in this file.

@GanGral GanGral closed this as completed Aug 16, 2023
@GanGral
Copy link
Author

GanGral commented Aug 16, 2023

I see couple of ways of fixing issue:

  • bring back mnist.pkl.gz to the repository (since it's missing currently) and make sure accessing fields by strings works there
  • change to code to access data using integers, not strings (this seem to work):

print(MNIST[0][0][0][130:180])
print(MNIST[0][1][0])
features = MNIST[0][0].astype(np.float32) / 256.0
labels = MNIST[0][1]
fig = pylab.figure(figsize=(10,5))
for i in range(10):
ax = fig.add_subplot(1,10,i+1)
pylab.imshow(features[i].reshape(28,28))
pylab.show()

@GanGral GanGral reopened this Aug 17, 2023
@cutePanda123
Copy link
Contributor

i fixed the 'ascii' code error by specifying the encoding parameter: MNIST = pickle.load(mnist_pickle, encoding='latin1')

link to the commit: cutePanda123@a73db3c

@liuyanhui
Copy link

It works , Thank you very much.

liuyanhui added a commit to liuyanhui/AI-For-Beginners that referenced this issue Aug 29, 2024
Add another url to download mnist.pkl.gz.
All the infos are from microsoft#241
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

3 participants