Python 3.x OutOfRangeError(回溯见上文):RandomShuffleQueue'_1总是出现,为什么?

Python 3.x OutOfRangeError(回溯见上文):RandomShuffleQueue'_1总是出现,为什么?,python-3.x,tensorflow,machine-learning,deep-learning,Python 3.x,Tensorflow,Machine Learning,Deep Learning,OutOfRangeError(回溯请参见上文):RandomShuffleQueue'\u 1\u shuffle\u batch/Randomy\u shuffle\u queue'已关闭且元素不足(请求15,当前大小10) 例外总是出现,而且是随机出现的,有时是180位,有时是170位。我的文件夹中有5890+个小jpg图像。它没有到达我的文件列表的末尾。我只是想知道为什么?这个问题花了我整整4个小时,没有解决办法。谁能帮我?非常感谢 请检查输出,查看是否存在任何形状不匹配错误 当我使用包

OutOfRangeError(回溯请参见上文):RandomShuffleQueue'\u 1\u shuffle\u batch/Randomy\u shuffle\u queue'已关闭且元素不足(请求15,当前大小10)


例外总是出现,而且是随机出现的,有时是180位,有时是170位。我的文件夹中有5890+个小jpg图像。它没有到达我的文件列表的末尾。我只是想知道为什么?这个问题花了我整整4个小时,没有解决办法。谁能帮我?非常感谢

请检查输出,查看是否存在任何形状不匹配错误


当我使用包含所有3个通道图像的数据集时,您共享的示例代码对我有效。后来我添加了一个灰度图像,并观察到您看到的错误

非常感谢!!我检查了我的文件夹,发现了3个隐藏的文件!!当我为文件名为file.endswith(“.jpg”)的文件添加“filelist=[os.path.join(“/Users/yuxiao/Desktop/test1/”,file)”的条件时,一切正常。我只是在我的谷歌云计算机上得到了错误信息,它没有出现在我自己的mbp计算机上。再次感谢~!
# -*- coding:UTF-8 -*-
import tensorflow as tf
import os

def picread(fileList):
    """
    读取狗图片并转换成张量
    :param fileList: 文件路径 + 名字的列表
    :return: 每张图片的张量
    """

    # 1. 构造文件队列
    file_queue = tf.train.string_input_producer(filelist)
    print(file_queue)
    # 2. 构造阅读器去读取图片内容(默认是按一张图片)
    reader = tf.WholeFileReader()
    key,value = reader.read(file_queue)

    # 3. 对读取的图片数据进行解码
    image = tf.image.decode_jpeg(value)

    # 4. 处理图片的大小(统一大小)
    image_resize = tf.image.resize_images(image,[200,200])

    image_resize.set_shape([200,200,3])  # 批处理要求形状必须固定

    # 4. 进行批处理
    image_batch = tf.train.shuffle_batch([image_resize],min_after_dequeue=10,batch_size=20,num_threads=1,capacity=40)

    return image_batch


if __name__ == "__main__":

    file_names = os.listdir("/Users/yuxiao/Desktop/test1/")
    filelist = [os.path.join("/Users/yuxiao/Desktop/test1/",file) for file in file_names]
    print(len(filelist))
    image_batch = picread(filelist)

    with tf.Session() as sess:
        sess.run(tf.local_variables_initializer())
        # 定义一个线程协调器
        coord = tf.train.Coordinator()

        # 开启读文件的线程
        threads = tf.train.start_queue_runners(sess,coord=coord)
        for i in range(200):
            print("第",i,"次")
            sess.run([image_batch])
        # 回收子线程
        coord.request_stop()
        coord.join(threads)