0

I'm using tensorflow on windows via through anaconda while it is using python 3.6. I am running this code (Here), but I received the following error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 110: invalid start byte enter image description here

Can anyone help me how to deal with this?

Thanks

Albert
  • 184
  • 3
  • 3
  • 14
  • This is very likely not tensorflow specific. Probably you are trying to print something that is not unicode, so you need to explicitly encode it. Source would help trace it down. – Mad Wombat Aug 17 '17 at 21:01
  • Did you [google](https://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s) the error? – o-90 Aug 17 '17 at 21:02
  • @gobrewers14 I did and found that this error is about windows and python, but I dont know how to fix it, each person says a solution in a vague way – Albert Aug 17 '17 at 21:03
  • @MadWombat I removed the tensorflow tag – Albert Aug 17 '17 at 21:05
  • The solutions are vague because each specific problem is different, and only a vague solution can be applied to other similar problems. You need to find out where the string containing the bad byte is coming from and how it got to be bad. Often it's because the code is assuming UTF-8 is correct but in fact a different encoding was used. – Mark Ransom Aug 17 '17 at 21:20
  • @MarkRansom, not sure how to do "You need to find out where the string containing the bad byte is coming from and how it got to be bad." :/ – Albert Aug 17 '17 at 21:28
  • Looks like you are processing image files. Take these files all out of the directory you are reading from and move them back 1 by 1 or in small groups depending on how many you have until you get the error. Once you know the file causing the issue you can debug with only that file to determine where the error is coming. – Jason Duncan Aug 18 '17 at 00:14
  • @JasonDuncan true! when I take all images out it works fine, as soon as it has to read images it gives me the error – Albert Aug 18 '17 at 00:30

1 Answers1

2

I dont know why but I had to change the following code

with tf.gfile.FastGFile(filename, 'r') as f:
    image_data = f.read()

to

 with tf.gfile.FastGFile(filename, 'rb') as f:
    image_data = f.read()

and the problem was solved!

Albert
  • 184
  • 3
  • 3
  • 14
  • 1
    That makes perfect sense actually. Binary files don't need to be converted to strings, so no `decode` will be called. It can't fail if it isn't called! – Mark Ransom Aug 18 '17 at 15:15