【问题标题】:OutOfRangeError (see above for traceback): RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closedOutOfRangeError(参见上面的回溯):RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' 已关闭
【发布时间】:2017-11-16 18:58:27
【问题描述】:

Tensorflow 1.3 Windows 7、Python 3.6

我遇到了这个错误:

OutOfRangeError (see above for traceback): RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 3, current size 0)
     [[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

我看过类似的帖子:

OutOfRangeError (see above for traceback): RandomShuffleQueue '_5_shuffle_batch_1/random_shuffle_queue' is closed and has insufficient elements

OutOfRangeError (see above for traceback): FIFOQueue '_1_batch/fifo_queue' is closed and has insufficient elements (requested 32, current size 0)

OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)

尝试了列出的解决方案(除了注释一个,我不明白)

这是我的代码:

#more testing tfrecords

创建 TFREcords

import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import imread, imresize
import os
import tensorflow as tf
import numpy
import cv2


#Gather image paths

DIR = r'C:\Users\Moondra\Desktop\DATA\IMAGE_2'

images = [os.path.join(DIR, image) for image in os.listdir(DIR)]

# len(images) is 41




def _bytes_feature(value):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))

def _int64_feature(value):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))

tfrecords_filename = 'testing_2.tfrecords'

writer = tf.python_io.TFRecordWriter(tfrecords_filename)

for image in images:
    img = cv2.imread(image)
    img = cv2.resize(img, (300, 300), interpolation=cv2.INTER_CUBIC)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = img.astype(np.float32)


    feature ={'train/image': _bytes_feature(tf.compat.as_bytes(img.tostring()))}



    example = tf.train.Example(features=tf.train.Features(feature=feature))
    writer.write(example.SerializeToString())

writer.close()

将 TFREcords 加载到批次中

#absolute path
tfrecords_filename = r'C:\Users\Moondra\Desktop\Transfer Learning Tutorials\testing_2.tfrecords'


with tf.Session() as sess:
    feature = {'train/image': tf.FixedLenFeature([],tf.string)
               }

    filename_queue = tf.train.string_input_producer([tfrecords_filename],num_epochs=1)
    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)

    features = tf.parse_single_example(serialized_example, features=feature)
    image = tf.decode_raw(features['train/image'], tf.float32)
    image = tf.reshape(image, [299, 299, 3])

    images = tf.train.shuffle_batch([image], batch_size=3, capacity=12, num_threads=1, min_after_dequeue=10)

    init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
    sess.run(init_op)
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)

    for batch_index in range(2):
        img  = sess.run([images])
        print(img.shape)
        img = img.astype(np.uint8)
        for j in range(6):
            plt.subplot(2, 3, j+1)
            plt.imshow(img[j, ...])
            plt.show()
    coord.request_stop()
    coord.join(threads)
    sess.close()

如果需要,我已将图像作为 zip 文件上传到我的 github:

https://github.com/moondra2017/Testing_Cat_classifier_Tensorflow

标记为 IMAGE_2.7z

谢谢。

【问题讨论】:

    标签: python-3.x tensorflow deep-learning


    【解决方案1】:

    我遇到了类似的问题,它是由 num_epochs=1 参数引起的(我将其增加到我的实际 epoch 数)。

    看到这个帖子:TensorFlow random_shuffle_queue is closed and has insufficient elements

    【讨论】:

      【解决方案2】:

      我之前也有同样的问题,但是很多答案都不好,最后我发现答案是如果我们想使用num_epochs,我们应该在[with tf.Session() as sess:]之前生成队列。

      【讨论】:

      • 使用edit 按钮以您想要的更改来更新答案。
      【解决方案3】:

      找出错误。

      我保存的尺寸是 [300,300]

      我尝试加载的维度是 [299,299]

      #Image = tf.reshape(image, [299, 299, 3])
      

      【讨论】:

      • 抱歉,我看不出这个问题与您在第一篇文章中显示的错误消息有什么关系。这与队列没有足够的元素有关。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多