tf.WholeFileReader公司()不读书

2024-09-29 06:22:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码似乎完美地找到了jpeg图像,因为如果我弄乱了路径,它将无法继续,而且我打印了一次match_filenames_的返回,并且有一个正确的图像文件列表。但是,下面的代码似乎没有将图像加载到队列中。文件名队列有什么问题?在

这是我的代码:

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)

输出如下:

^{pr2}$

Tags: 代码图像image队列queuetfmatchtrain
1条回答
网友
1楼 · 发布于 2024-09-29 06:22:40

尝试打印image_tensor的形状

print(image_tensor.shape)

代码中的image是张量,它的大小未知,因为它是从任意jpeg图像生成的图形,而TF无法定义它的大小,当TF创建graph时。但是image_tensor是{},图像从磁盘加载。在

相关问题 更多 >