python - tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue
问题描述
我正在从 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)
但不要帮助我。
解决方案
我已经解决了这个问题。需要处理值“gt2d”,因为某些值为负数会导致裁剪图像大小不匹配。
推荐阅读
- razor - 为什么模型数据从视图传递到控制器为空?
- mongodb - 如果发出并发请求,与 docker 容器的连接会丢失
- css - 你可以在 CSS 速记属性中使用 Sass 变量吗?
- sql-server - 即使我发布一个值,Spring data JPA也会将null插入列错误?
- javascript - 使用 jq 和 node.js 转换 ec2 标签
- autodesk-forge - 在查看器 401 错误中加载新上传的模型
- python-3.x - 将秒转换为小时、分钟和秒
- javascript - Leaflet-geoman 如何正确检索 GeoJSON
- amazon-web-services - Cloudformation 未更新 TaskDefinition 修订版
- javascript - 当 5 个复杂输入中至少有 1 个有效时提交表单