Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第七章图片预处理关于完整样例中读取文件报错 #60

Closed
saselovejulie opened this issue Jul 19, 2017 · 8 comments
Closed

Comments

@saselovejulie
Copy link

image_raw_data = tf.gfile.FastGFile("../../datasets/cat.jpg", "r").read()
代码中读取图片的代码. 在我本地报错.UnicodeDecodeError: 'utf-8' codec can't decode byte error


image_raw_data = tf.gfile.FastGFile("../../datasets/cat.jpg", "r").read()
改为
image_raw_data = tf.gfile.FastGFile("../../datasets/cat.jpg", "rb").read()
错误消失, 我初学python,查了一下rb是读取二进制文件.
请问老师是否要改成rb?
谢谢
1500480054

@ScorpioCPH
Copy link
Contributor

@saselovejulie
脚本里面,最前面加上下面这句试下:

# coding=utf-8

@saselovejulie
Copy link
Author

@ScorpioCPH
加上了还是有这个issue, 麻烦有时间看看.谢谢
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

@saselovejulie
Copy link
Author

1500553139

@ScorpioCPH
Copy link
Contributor

试一下下面这个代码,测试过可以正常工作:

# coding=utf-8

import tensorflow as tf

# cat.jpg 放到相同目录
image_raw_data = tf.gfile.FastGFile("./cat.jpg",'r').read()

with tf.Session() as sess:
    img_data = tf.image.decode_jpeg(image_raw_data)
    
    # 输出解码之后的三维矩阵
    print 'img_data: ', img_data.eval()
    img_data.set_shape([1797, 2673, 3])
    print 'img_shape: ', img_data.get_shape()

PS,你用的 python 2 还是 3

@ScorpioCPH
Copy link
Contributor

@saselovejulie

@saselovejulie
Copy link
Author

@ScorpioCPH
谢谢, 我试试.
我是Python3.5

@saselovejulie
Copy link
Author

@ScorpioCPH
你给我的代码还是改成rb, 看来是python版本问题...
thanks

@ScorpioCPH
Copy link
Contributor

我用的 python 2.7,那可能是版本的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants