1. 程式人生 > >TensorFlow學習筆記(UTF-8 問題解決 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)

TensorFlow學習筆記(UTF-8 問題解決 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)

show 學習 github red star ims fas can pri

我使用VS2013 Python3.5 TensorFlow 1.3 的開發環境

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

在是使用Tensorflow讀取圖片文件的情況下,會出現這個報錯

代碼如下

# -*- coding: utf-8 -*-
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt


image_raw_data = tf.gfile.FastGFile(name = ‘sse.jpg‘, mode =‘r‘).read()


with tf.Session() as sess:
    img_data = tf.image.decode_jpeg(image_raw_data)    

    print(img_data.eval())

    plt.imshow(img_data.eval())

    plt.show()

  出現的報錯如下:

技術分享

度娘沒有查找到結果,Google上找到了相應的解決方案

1 image_raw_data
2 
3 image_raw_data = tf.gfile.FastGFile(sse.jpg, r).read()
4 # 替換為:
5 image_raw_data= tf.gfile.FastGFile(sse.jpg, rb).read()

解決方案地址:https://github.com/balancap/SSD-Tensorflow/issues/108

TensorFlow學習筆記(UTF-8 問題解決 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte)