2017-05-05 84 views
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) 
+0

相同的代碼爲我工作。使用以下來顯示圖像。從PIL導入圖像; img = Image.fromarray(image_tensor,'RGB'); img.show() – hars

+0

我真的這樣做了,但沒有包括在內,因爲它並不重要。輸出只是黑色的圖像。 – marko

回答

2

您的代碼是正確的。 我與圖像有相同的問題從Kaggle competition

似乎像Tensorflow dectes這些文件的色彩空間不合適,或圖像中編碼的cloorspace信息不正確。

看起來像Tensorflow不允許在解碼圖像時執行色彩空間。所以最簡單的方法是「修復」圖像。從ImageMagic工具箱

我使用「轉換」實用工具:

ls train-jpg/ | \ 
     parallel convert -colorspace sRGB train-jpg/{} fixed-train-jpg/{}