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文件即可.
随机推荐
- NOSQL之REDIS
Redis是NoSQL中比较常典型的一个非关系型数据库,在日常工作中也是最为常见的.Redis是一个由C语言编写的开源的.遵守BSD协议.支持网络.可基于内存亦可持久化的日志型.Key-Value数据 ...
- 出现“安全时间戳无效,因为其创建时间(“2013-10-30T14:42:07.861Z”)是将来的时间。当前时间为“2013-10-30T14:36:23.988Z”,允许的时钟偏差是“00:05:00””的原因
具体原因是服务器的时间和本地的时间不能超过5分钟,超过5分钟了.只要修改你本地机器的时间,和服务器相差的时间不能超过5分钟,就可以了. 根本原因是windows 系统域认证要求的,所有都一样.
- myeclipse修改编译器版本的方法 .
今天在导入一个工程时,发现出现java.lang.UnsupportedClassVersionError: Bad version number in .class file异常,检查了一下我的my ...
- android 布局入门
一.LinearLayout RelativeLayout 这俩的区别详见这里 http://www.cnblogs.com/duanweishi/p/4244233.html 二.android:l ...
- LwIP raw api下使用tcp keep alive
// The following code is implemented after tcp_new() or in tcp_connected call back... xxx_connected( ...
- request笔记记录
1.https请求报错解决方法,添加verify=False参数 r = requests.get(json=payload, headers=headers,verify=False) 1)由于这里 ...
- 学习笔记之Docker
Docker 官网 http://www.docker.com Docker is the company driving the container movement and the only co ...
- Linux期中架构 全网备份案例
server端脚本 #!/bin/bash #1 进行数据完整性验证 并生成结果 find /backup -type f -name "finger.txt"| xargs md ...
- [UE4]让AI跑起来
让AI由静止状态变成跑步状态,做法跟玩家角色走路一样. 一.创建1D混合动画 二.在AI角色关联的动画蓝图中使用第一步创建的混合动画
- javascript控制滚动条的位置,获取控件的位置
一.如下是定位鼠标在视窗中的位置,先定位视窗和页面直接的距离. function getMousePoint() { var point = {x:0,y:0}; // 如果浏览器支持 pageYOf ...