2017-07-25 67 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

正确的,现在有意义 –