tensorflow UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
tensorflow读取图像出现错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
#!/usr/bin/python
# -*- coding: utf-8 -*- import matplotlib.pyplot as plt
import tensorflow as tf filename = "/home/zzz/1-Work/Documents/2-Codes/learning/tf/17flowers/jpg/0/image_0001.jpg"
image_raw_data = tf.gfile.FastGFile(filename, "r").read() # 问题出在这里,mode应该为“rb”而不是“r” with tf.Session() as sess:
img_data = tf.image.decode_jpeg(image_raw_data)
tmp = img_data.eval()
print(tmp)
plt.imshow(tmp)
plt.show()
img_data = tf.image.convert_image_dtype(img_data, dtype=tf.uint8)
encoded_img = tf.image.encode_jpeg(img_data)
with tf.gfile.GFile("/home/zzz/tf_tmp", "wb") as f:
f.write(encoded_img.eval())
原因:在
image_raw_data = tf.gfile.FastGFile(filename, "r").read()
这一行,读取的时候读取方式应该是“rb”,在读取模式只使用“r”的时候,python试图将一个byte-array转成utf-8字符串,这样python就会遇到utf-8的非法字符: 0xff in position 0,遇到这种情况时,可以将读取方式改为“rb”,这样在读取数据的时候,会将数据按照二进制读取,就不会有上述的解码问题。
ps:引起这个问题的另一个原因可能是所要读取的数据是按照utf-16编码的,在这种情况下,可以加关键字参数,encoding=“utf-16”解决。
tensorflow 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)
我使用VS2013 Python3.5 TensorFlow 1.3 的开发环境 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff ...
- TensorFlow学习('utf-8' codec can't decode byte 0xff in position 0: invalid start byte)
使用语句: image_raw_data = tf.gfile.GFile("./picture.jpg", "r").read() 读取图像时报错如下: Un ...
- 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 觉得有用的话,欢迎一起讨论相互学习~Follow Me 今 ...
- Python:出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 0: invalid continuation byte问题
我在导入一个csv文件的时候出现了一个问题 报错的内容是这样的: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in positio ...
- Pandas读取文件报错UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte
pandas读取文件时报UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start by ...
- binlog2sql 解析日志失败 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 0: invalid start byte
python35 ./binlog2sql.py -h... -P... -u... -p... -B --start-file="mysql-bin.091940" --star ...
- 第一篇:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
需求:python如何实现普通用户登录服务器后切换到root用户再执行命令 解决参考: 代码: def verification_ssh(host,username,password,port,roo ...
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
需求:python如何实现普通用户登录服务器后切换到root用户再执行命令 解决参考: 代码: def verification_ssh(host,username,password,port,roo ...
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
用pandas打开csv文件可能会出现这种情况,原因可能是excel自己新建一个*.csv文件时候容易出错.进入文件另存为,然后选择csv文件即可.
随机推荐
- 4.图像sensor的特性和驱动解析
修改 摄像头SDK中支持的sensor需要做的事 例如:ar0130 --> ov9712 1.修改加载load3518e脚本的参数 vi /etc/profile ./load3518e -i ...
- 【转】【iOS】动态更换App图标
原文网址:http://www.cocoachina.com/ios/20170619/19557.html 前言 动态更换App图标这件事,在用户里总是存在需求的:有些用户喜欢“美化”自己的手机.至 ...
- FineUI中在一个页面中通过控件事件(JS)向父页面中添加Tab页
1.在前台页面尾部添加js代码 </form> <script type="text/javascript"> var basePath ...
- kvm 基本运维命令
Kvm基本命令 一.查询命令 1.列出所有的虚拟机 virsh list –all 2.显示虚拟机信息 virsh dominfo kvm-1 3.显示虚拟机内存和cpu的使用情况 yum insta ...
- 树莓派3代B型 Raspberry Pi Model 3 B 安装 centos7系统
板子类型: Raspberry Pi Model 3 B 搭配 32G的SD卡: 下载支持树莓派版本的centos7系统 https://buildlogs.centos.org/centos/7/i ...
- 转【Oracle】一款非常好用的trace文件分析工具
[Oracle]一款非常好用的trace文件分析工具之一 北在南方 2016-04-14 11:23:58 浏览547 评论0 摘要: 介绍一款非常好用的10046分析工具--trca(Trace ...
- golang之void*类型可变数组例子
package main import ( "fmt" ) type TestStruct struct { aa string name string } type Object ...
- 关于 ake sure class name exists, is public, and has an empty constructor that is public
解决方法:自定义的fragment最好有一个Public的参数为空的构造函数,若需要传入一个参数,可以使用下面的方法 public FileViewFragment(){ } public stati ...
- 【Spring实战-3】Spring整合Hibernate、Struts
作者:ssslinppp 1. 摘要 版本: Spring4.0.4:Hibernate4.3.5:struts2.3.16: 主要介绍了如下内容: 项目结构的规划: Spring下整合Hi ...
- 杂项:CDN
ylbtech-杂项:CDN CDN的全称是Content Delivery Network,即内容分发网络.其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快 ...