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

python 3.6.5 Anaconda still gives this error for

f = gzip.open('mnist.pkl.gz', 'rb') training_data, validation_data, test_data = pickle.load(f, encoding="latin1") f.close()

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 22
  • Comments: 23

Most upvoted comments

Turns out that un-pickling in Python 3 needs some decoding. As explained here. Basically, after opening on gzip, try the following,

u = pickle._Unpickler( f ) u.encoding = 'latin1' train, val, test = u.load()

Try from this repo

!git clone https://github.com/MichalDanielDobrzanski/DeepLearningPython35.git
!ls
import pickle
import gzip
import numpy as np

f = gzip.open("./DeepLearningPython35/mnist.pkl.gz")
training_data, validation_data, test_data = pickle.load(f, encoding="latin1")
print(training_data)

Try from this repo

!git clone https://github.com/MichalDanielDobrzanski/DeepLearningPython35.git
!ls
import pickle
import gzip
import numpy as np

f = gzip.open("./DeepLearningPython35/mnist.pkl.gz")
training_data, validation_data, test_data = pickle.load(f, encoding="latin1")
print(training_data)

even after setting encoding as latin1, it’s still giving the same

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0x90 in position 614: ordinal not in range(128) somehow it’s not recognizing the encoding that I set?

if you are working on notebook, please shutdown the project and reconnect and then run the code to see. It works for me after such refresh.

In python 3.9 you have to use named parameters like so:

import _pickle as cPickle imported = cPickle.Unpickler(file=f, encoding=‘latin1’) training_data, validation_data, test_data = imported.load()

The code provided by @ppatel26 is functional in Python 3.8.2.

Turns out that un-pickling in Python 3 needs some decoding. As explained here. Basically, after opening on gzip, try the following,

u = pickle._Unpickler( f ) u.encoding = 'latin1' train, val, test = u.load()

Works! Thank you 😃 @shashankravi96