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的~

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