tensorflow.python.framework.errors_impl.OutOfRangeError:RandomShuffleQueue

时间:2019-01-05 16:22:43

标签: python tensorflow

我正在从tfrecords中读取一批图像。 当我使用它时,我的代码是正确的。

image_ori, image_human, image_human_size, center, fname, pose, shape, gt2d, gt3d, seg = 
    data_utils.parse_example_proto(example_serialized)
image = tf.image.resize_images(seg, (224, 224), method=0)

但是,如果我对图像进行一些预处理,如下所示:

image_ori, image_human, image_human_size, center, fname, pose, shape, gt2d, gt3d, seg = 
    data_utils.parse_example_proto(example_serialized)

image, gt2d = self.image_preprocessing(image_ori, center, gt2d, pose=None, gt3d=None)

def image_preprocessing(self, image, center, gt2d, pose=None, gt3d=None):
    margin = tf.to_int32(self.output_size / 2)
    image_size = tf.constant([240, 320], shape=[2, ])
    with tf.name_scope(None, 'image_preprocessing', [image, center, gt2d]):
        keypoints = tf.transpose(gt2d[:, :])

        # Randomly shift center.
        center = data_utils.jitter_center(center, self.trans_max)
        # randomly scale image.
        image, keypoints, center = data_utils.jitter_scale(
            image, image_size, keypoints, center, self.scale_range)

        # Pad image with safe margin.
        # Extra 50 for safety.
        margin_safe = margin + self.trans_max + 50
        image_pad = data_utils.pad_image_edge(image, margin_safe)
        center_pad = center + margin_safe
        keypoints_pad = keypoints + tf.to_float(margin_safe)
        start_pt = center_pad - margin

        # Crop image pad.
        start_pt = tf.squeeze(start_pt)
        bbox_begin = tf.stack([start_pt[1], start_pt[0], 0])
        bbox_size = tf.stack([self.output_size, self.output_size, 3])

        crop = tf.slice(image_pad, bbox_begin, bbox_size)
        x_crop = keypoints_pad[0, :] - tf.to_float(start_pt[0])
        y_crop = keypoints_pad[1, :] - tf.to_float(start_pt[1])

        crop_kp = tf.stack([x_crop, y_crop])

        if pose is not None:
            crop, crop_kp, new_pose, new_gt3d = data_utils.random_flip(
                crop, crop_kp, pose, gt3d)
        else:
            crop, crop_kp = data_utils.random_flip(crop, crop_kp)

        # Normalize kp output to [-1, 1]
        final_label = 2.0 * (crop_kp / self.output_size) - 1.0

        # rescale image from [0, 1] to [-1, 1]
        crop = data_utils.rescale_image(crop)

        if pose is not None:
            return crop, tf.transpose(final_label), new_pose, new_gt3d
        else:
            return crop, tf.transpose(final_label)

我确认函数data_utils.parse_example_proto是正确的,因为前者可以运行。

错误如下:

tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_4_input_batch_train_1/random_shuffle_queue' is closed an d has insufficient elements (requested 32, current size 22)                                                                           
[[Node: input_batch_train_1 = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT] , timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0 (input_batch_train_1/random_shuffle_queue, input_batch_train_1/n)]]  

该错误不会在一开始出现,而是在执行以下步骤后出现:

[itr 569/epoch 1]: loss_pose: 0.0386:  20%|███████████▎            570/2812

一开始我发现别人的错误是这样的

(requested 32, current size 0)

为什么我的错误发生在中间?

我使用了一些方法:

init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
sess.run(init_op)

但别帮我。

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。 需要处理'gt2d'值,因为有些值是负数,这会导致作物图像尺寸不匹配。