python如何读取tfrecord文件_尝试从多个tfrecord文件读取数据

我有一个.tfrecords文件的文件夹,我想将这些文件读入网络。但是,我在一次读取多个tfrecords文件时遇到了很多麻烦。在

我的所有tfrecords文件都存储在path_to_folders列表中。我所有的功能名称都是正确的。在

我的代码如下:with tf.Session() as sess:

for folder in path_to_folders:

try:

no_grasps = int(len(os.listdir(folder)) / 5)

feature_name_images = os.path.basename(folder) + '_images'

feature_name_csv = os.path.basename(folder) + '_csv'

data_path = os.path.join(path_to_data, os.path.basename(folder) + '.tfrecords')

feature = {feature_name_images: tf.FixedLenFeature([], tf.string),

feature_name_csv: tf.FixedLenFeature([], tf.string)

}

filename_queue = tf.train.string_input_producer([data_path], num_epochs=1)

reader = tf.TFRecordReader()

_, serialized_example = reader.read(filename_queue)

features = tf.parse_single_example(serialized_example, features=feature)

image_out = tf.decode_raw(features[feature_name_images], tf.float32)

csv_out = tf.decode_raw(features[feature_name_csv], tf.float32)

image_out_reshaped = tf.reshape(image_out, [no_grasps, 200, 200, 3])

csv_out_reshaped = tf.reshape(csv_out, [no_grasps, 6])

sess.run(tf.global_variables_initializer())

sess.run(tf.local_variables_initializer())

# Create a coordinator and run all QueueRunner objects

coord = tf.train.Coordinator()

threads = tf.train.start_queue_runners(coord=coord)

# image_dataset, csv_dataset = sess.run([image_out_reshaped, csv_out_reshaped])

image_dataset = sess.run(image_out_reshaped)

coord.request_stop()

coord.join(threads)

print(image_dataset.shape, type(image_dataset))

time.sleep(2)

except tf.errors.OutOfRangeError:

print('epoch limit reached')

在读取的第一次迭代完成后(第一个tfrecords文件成功读取),然后其余的文件告诉我已达到epoch限制,并警告:

^{pr2}$

我真的不明白为什么会这样,我想知道是否有人能帮我。在

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值