1
我正在使用一個腳本將圖像加載到TensorFlow,它顯然適用於所有人,但是當我嘗試它時,最終會出現黑色圖像(零矩陣)。我嘗試了幾個圖像文件,並且它始終爲零,並且當我故意拼錯圖像位置字符串時,它會報告錯誤(因爲它應該)。返回的圖像張量的大小是正確的(256,256,3)
。這是腳本,有人看到錯誤?tf.image.decode_jpeg()返回零矩陣
file_names = ['/home/marko/Data/train_27.jpg']
filename_queue = tf.train.string_input_producer(file_names)
image_reader = tf.WholeFileReader()
title, image_file = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_file,channels=3)
with tf.Session() as sess:
tf.global_variables_initializer().run()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
image_tensor = sess.run(image)
print(image_tensor)
print(image_tensor.shape)
coord.request_stop()
coord.join(threads)
相同的代碼爲我工作。使用以下來顯示圖像。從PIL導入圖像; img = Image.fromarray(image_tensor,'RGB'); img.show() – hars
我真的這樣做了,但沒有包括在內,因爲它並不重要。輸出只是黑色的圖像。 – marko