zishansami102 / CNN-from-Scratch

A scratch implementation of Convolutional Neural Network in Python using only numpy and validated over CIFAR-10 & MNIST Dataset
http://cnndigits.pythonanywhere.com/
GNU General Public License v3.0
271 stars 79 forks source link

UnicodeDecodeError when running app.py #14

Closed dennisfurrer closed 5 years ago

dennisfurrer commented 6 years ago

I am using Python 3.7 on MacOS. I trained the CNN with the MNIST db and tried running app.py While it starts and I can access it from 127.0.0.1:5000, as soon as I draw a digit and press Predict I get the following console output.


AdityaSoni19031997 commented 6 years ago

Ain't sure (not a Mac user) but it seems it's just a codec error specific to MAC..

dennisfurrer commented 6 years ago

Any ideas on how to fix it? @AdityaSoni19031997

AdityaSoni19031997 commented 6 years ago

If we are lucky, then it should be solved by passing in the encoding parameter while opening that pickle file or try to include this on the top of that file"# -- coding: utf-8 --" or check this discussion https://stackoverflow.com/questions/21129020/how-to-fix-unicodedecodeerror-ascii-codec-cant-decode-byte

dennisfurrer commented 6 years ago

Could you clarify which file you mean? I assumed it was the trained.pickle file but that resulted in an error " _pickle.UnpicklingError: invalid load key, '#'. "

Thank you in advance for your help @AdityaSoni19031997

AdityaSoni19031997 commented 6 years ago

It has been quite a while since I ran the code.. but the last line of the traceback where we are opening the pickle file, we might change the encoding...

If nothing works, then we can comment out the flask part maybe ! I am out of ideas as of now..(Sorry for that)

dennisfurrer commented 6 years ago

You mean by adding the encoding type to replace this:

pickle_in = open(PICKLE_FILE, 'rb')

with this:

pickle_in = open(PICKLE_FILE, 'rb', "encoding=utf-8")

?

Then I get the following error: " ValueError: binary mode doesn't take an encoding argument "

AdityaSoni19031997 commented 6 years ago

Why the rb, only r should do ? PS I ain't sure but for me it's was always the encoding parameter which I mess up, so fixing that fixes stuff for me..

AdityaSoni19031997 commented 6 years ago

pickle_in = open(PICKLE_FILE, 'r', encoding='utf-8');

dennisfurrer commented 6 years ago

thats the code thats on this repository? I'll try replacing it with 'r'

dennisfurrer commented 6 years ago

I now get " TypeError: a bytes-like object is required, not 'str' "

nitinseven commented 6 years ago

same error I also got on windows with python 3.5 UnicodeDecodeError: 'ascii' codec can't decode byte 0xca in position 0: ordinal not in range(128)

any solution?

yanatarkhaeva commented 5 years ago

I assume the solution is to train this network on your Python 3.x and then save the result using pickle (the pickle which is for the third version of Python). So when you'll predict it would unpack the file which is saved by the same module. But this will take approximately 80 hours (on my not-so-powerfull laptop). That's the thing I'm now struggling on. Because I need to learn a neural network of this type by the next day and it's still 50 hours remaining. So if someone has an opportunity to train the network on MNIST dataset faster then me, share the resulting output.pickle file here, please. (English isn't my first language sorry if I made mistakes.)

dennisfurrer commented 5 years ago

Hope this helps @yanatarkhaeva https://github.com/dennisfurrer/cnn-output-pickle

AdityaSoni19031997 commented 5 years ago

You can use kaggle kernels/Colab/free GPU to train

AdityaSoni19031997 commented 5 years ago

Bytes like object might mean the way we are opening or creating or passing the file name isn't correct ... Happened with me few days back