UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
程序员文章站
2024-02-22 11:38:46
...
原代码:
import matplotlib.pyplot as plt
import tensorflow as tf
#读取图像的原始数据
image_raw_data = tf.gfile.FastGFile('dog.jpg','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()
encoded_image = tf.image.encode_jpeg(img_data)
with tf.gfile.GFile('output.jpg','wb') as f:
f.write(encoded_image.eval())
只用修改读取图像时的权限就行,把
image_raw_data = tf.gfile.FastGFile('dog.jpg','r').read()改为
image_raw_data = tf.gfile.FastGFile('dog.jpg','rb').read()就好了。
上一篇: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte解决方法
下一篇: PHP微信开发之有道翻译
推荐阅读
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte解决方法
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 问题
-
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
-
调试错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
-
pickle报UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xff in position 0:
-
RLException: Invalid <node> tag: ‘ascii‘ codec can‘t decode byte 0xe6报错
-
Anaconda中启动Python时的错误:UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 553
-
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xcb in position 260: ordinal not in range(128)
-
命令行调用python出现编码错误:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x9a in position 140 完美解决!