2017-07-25 96 views
0

我的代碼似乎完美地找到了jpeg圖像,因爲如果我搞亂了路徑,它將不會繼續,我還打印出match_filenames_once的返回,並且存在正確的圖像文件列表。但是下面的代碼似乎沒有將圖像加載到隊列中。 filename_queue有什麼問題?tf.WholeFileReader()not reading

這裏是我的代碼:

filename_queue = tf.train.string_input_producer(
tf.train.match_filenames_once("./resized2/*.jpg"),shuffle=False) 

image_reader = tf.WholeFileReader() 
myfilename, image_file = image_reader.read(filename_queue) 
image = tf.image.decode_jpeg(image_file) 
# Start a new session to show example output. 

with tf.Session() as sess: 
    init_op = tf.global_variables_initializer(), tf.local_variables_initializer() 

    sess.run(init_op) 

    # Start populating the filename queue. 

    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 

    for i in range(1): #length of your filename list 
     image_tensor = image.eval() #here is your image Tensor :) 
    print(myfilename) 
    print(image.shape) 
    #Image.fromarray(np.asarray(image_tensor)).show() 

    coord.request_stop() 
    coord.join(threads) 

這裏是輸出:

Tensor("ReaderReadV2:0", shape=(), dtype=string) 
(?, ?, ?) 
+0

你的意思是 - 'print(image_tensor.shape)'? –

+0

是的,打印出(225,300,3),這是圖像的尺寸 –

回答

0

嘗試打印的image_tensor

print(image_tensor.shape) 

image形狀在你的代碼是張量,它具有未知的大小,因爲它從任意的jpeg圖像開始繪製圖形,並且TF無法解析當TF創建圖形時,它的尺寸很大。但image_tensornp.array從磁盤加載圖像。

+0

正確的,現在有意義 –