tensorflow查看自己的图片数据报错UnicodeEncodeError

在Spyder中想要用自己的图片数据进行训练时,tf.image.decode_jpeg(png就是tf.image.decode_png)解码后,想要看下图片,结果报错:

UnicodeEncodeError: 'utf-8' codec can't encode character '\udcd5' in position 1892: surrogates not allowed

原本的程序如下:

import tensorflow as tf
import matplotlib.pyplot as plt

test_file=tf.read_file('F:\\图片数据\\girl_1.jpg')
test_image=tf.image.decode_jpeg(test_file,channels=3)

sess = tf.Session()
sess.run(tf.global_variables_initializer())

img=sess.run((test_image))

plt.imshow(img)

自己瞎搞了半天,终于试出来了,罪魁祸首在这!!

test_file=tf.read_file('F:\\图片数据\\girl_1.jpg')

貌似read_file不支持中文路径,去掉中文的就ok了

test_file=tf.read_file('F:\\girl_1.jpg')

看看小姐姐

因为用的是Spyder,所以图片直接就出来了。在idle中试了下,图片没有直接出来,而是保存到内存地址中了。我也没去试怎么让它显示出来,嘛,毕竟一般都不会用idle的~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章