TensorFlow导入图片报错

用TensorFlow导入图片时报错UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

TensorFlow导入图片报错

使用的是tf.gfile.FastGFile()函数,上网查了一下,该函数描述如下:

tf.gfile.FastGFile(path,decodestyle) 
函数功能:实现对图片的读取。 
函数参数:(1)path:图片所在路径 (2)decodestyle:图片的解码方式。(‘r’:UTF-8编码; ‘rb’:非UTF-8编码)

问题解决方法:

image_raw_data_jpg = tf.gfile.FastGFile('LIVE/wn/1.jpg','r').read()

替换成

image_raw_data_jpg = tf.gfile.FastGFile('LIVE/wn/1.jpg','rb').read()

 

参考:

https://blog.****.net/chen645096127/article/details/79079388