DeepLearningPython icon indicating copy to clipboard operation
DeepLearningPython copied to clipboard

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

Open ppatel26 opened this issue 6 years ago • 22 comments

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()

ppatel26 avatar Oct 11 '18 06:10 ppatel26

Works fine.

ppatel26 avatar Oct 12 '18 18:10 ppatel26

I am facing the same problem. In fact code

f = gzip.open('neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb') training_data, validation_data, test_data = pickle.load(f,encoding='bytes') f.close()

OR

with gzip.open('neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb') as ff: u=pickle._Unpickler(ff) u.encoding='latin1'

training_data, validation_data, test_data=u.load()

both are giving the same following error

training_data , validation_data , test_data = mnist_loader.load_data_wrapper() Traceback (most recent call last): File "", line 1, in File "C:\Users\rkd\Desktop\NN-DL\mnist_loader.py", line 61, in load_data_wrapper numpy.ndarry containing the input image, and y is the File "C:\Users\rkd\Desktop\NN-DL\mnist_loader.py", line 39, in load_data # training_data, validation_data, test_data = pickle.load(f,encoding='bytes') UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128) I would appreciate your help in this regard.

best wishes Ritesh

yebud avatar Jun 02 '19 09:06 yebud

How to resolve that issue @ppatel26 ?

ChampionTej05 avatar Sep 13 '19 17:09 ChampionTej05

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()

shashankravi96 avatar Feb 24 '20 18:02 shashankravi96

lo que menciona shashankravi96 funciona perfecto! gracias

pabloverdier avatar Apr 08 '20 23:04 pabloverdier

I am facing the same problem. In fact code

f = gzip.open('neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb') training_data, validation_data, test_data = pickle.load(f,encoding='bytes') f.close()

OR

with gzip.open('neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb') as ff: u=pickle._Unpickler(ff) u.encoding='latin1'

training_data, validation_data, test_data=u.load()

both are giving the same following error

training_data , validation_data , test_data = mnist_loader.load_data_wrapper() Traceback (most recent call last): File "", line 1, in File "C:\Users\rkd\Desktop\NN-DL\mnist_loader.py", line 61, in load_data_wrapper numpy.ndarry containing the input image, and y is the File "C:\Users\rkd\Desktop\NN-DL\mnist_loader.py", line 39, in load_data

training_data, validation_data, test_data = pickle.load(f,encoding='bytes')

UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128) I would appreciate your help in this regard.

best wishes Ritesh

Hi yebud! I just started 'neural-networks-and-deep-learning' a few days ago and I am stuck right now. I saw you used this learning material as well, is there any chance I can contact you? I want to learn from your valuable experience.

All the best, Thank you!

ghost avatar Apr 21 '20 10:04 ghost

Hi,

this is the one that works for me. I am using Python from Spyder from Anaconda...

El mar., 21 de abr. de 2020 a la(s) 03:19, Poramintrl ( [email protected]) escribió:

I am facing the same problem. In fact code

f = gzip.open('neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb') training_data, validation_data, test_data = pickle.load(f,encoding='bytes') f.close()

OR

with gzip.open('neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb') as ff: u=pickle._Unpickler(ff) u.encoding='latin1'

training_data, validation_data, test_data=u.load()

both are giving the same following error

training_data , validation_data , test_data = mnist_loader.load_data_wrapper() Traceback (most recent call last): File "", line 1, in File "C:\Users\rkd\Desktop\NN-DL\mnist_loader.py", line 61, in load_data_wrapper numpy.ndarry containing the input image, and y is the File "C:\Users\rkd\Desktop\NN-DL\mnist_loader.py", line 39, in load_data training_data, validation_data, test_data = pickle.load(f,encoding='bytes')

UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128) I would appreciate your help in this regard.

best wishes Ritesh

Hi yebud! I just started 'neural-networks-and-deep-learning' a few days ago and I am stuck right now. I saw you used this learning material as well, is there any chance I can contact you? I want to learn from your valuable experience.

All the best, Thank you!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MichalDanielDobrzanski/DeepLearningPython35/issues/15#issuecomment-617090137, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO7HKCCT4ICSLVW34HHCBN3RNVXLPANCNFSM4F23OOSA .

pabloverdier avatar Apr 21 '20 17:04 pabloverdier

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

abhishekshd avatar May 09 '20 19:05 abhishekshd

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

Willt125 avatar Jun 12 '20 23:06 Willt125

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()

brilliant, It works for me in Colab, thanks

shaopengwu avatar Sep 09 '20 20:09 shaopengwu

I'm really lost, I'm relatively new to coding and whenever I try a solution for the mnist_loader file I get an error message that I don't understand. I don't suppose someone could put an example of a complete python file that I could just copy and paste? That would be amazing...

benradick avatar Oct 04 '20 11:10 benradick

I'm really lost, I'm relatively new to coding and whenever I try a solution for the mnist_loader file I get an error message that I don't understand. I don't suppose someone could put an example of a complete python file that I could just copy and paste? That would be amazing...

Try codes below in Colab

!git clone https://github.com/mnielsen/neural-networks-and-deep-learning.git
import pickle
import gzip
import numpy as np

f = gzip.open("./neural-networks-and-deep-learning/data/mnist.pkl.gz")
training_data, validation_data, test_data = pickle.load(f, encoding="latin1")
print(training_data)

shaopengwu avatar Oct 04 '20 14:10 shaopengwu

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)

shaopengwu avatar Oct 04 '20 14:10 shaopengwu

Thankyou for your help shaopengwu!

Unfortunately I don't understand what this does - the output from Colab is:

Cloning into 'neural-networks-and-deep-learning'... remote: Enumerating objects: 1163, done. remote: Total 1163 (delta 0), reused 0 (delta 0), pack-reused 1163 Receiving objects: 100% (1163/1163), 20.42 MiB | 14.01 MiB/s, done. Resolving deltas: 100% (577/577), done. (array([[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], dtype=float32), array([5, 0, 4, ..., 8, 4, 8]))

What does this mean? How does this help me?

benradick avatar Oct 04 '20 15:10 benradick

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)

this worked well thank u so much

nickan2c avatar Oct 13 '20 11:10 nickan2c

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?

manchitro avatar Nov 21 '20 06:11 manchitro

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.

qiongwu60607 avatar Mar 17 '21 20:03 qiongwu60607

I dont know why not actualize the code for python3. After all why bother leave the book on line If you can use the code to study? The code worked only in the jupyter notebook! Paulo

schlogl2017 avatar Mar 18 '21 20:03 schlogl2017

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()

This worked for me.

bharathkreddy avatar Apr 19 '21 13:04 bharathkreddy

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()

makingglitches avatar Jun 26 '21 23:06 makingglitches

There are multiple issues on chapter 1 in respect of python2 -> 3:

  1. print "string" -> print("string")
  2. xrange(some list) -> range(some list)
  3. ...._data = zip(..._inputs) -> ...._data = list(zip(..._inputs)) Then it runs in 3.7

Ambusy avatar Nov 04 '21 14:11 Ambusy

For the people, who still struggling with it, just change the code into: f = gzip.open('../data/mnist.pkl.gz', 'rb') u = cPickle.Unpickler(file=f, encoding='latin1') training_data, validation_data, test_data = u.load() f.close() return (training_data, validation_data, test_data) return (training_data, validation_data, test_data)

Mh60682 avatar Jan 17 '22 06:01 Mh60682

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()

This worked for me. Thanks a lot!

carlosreiakvam-uit avatar Nov 15 '22 02:11 carlosreiakvam-uit