【问题标题】:Lost data when read from TFRecords从 TFRecords 读取时丢失数据
【发布时间】:2018-02-10 23:58:10
【问题描述】:

我正在创建 tfrecords 文件并从 tfrecords 读取数据。 tfrecord 有两个特征,vehicleid 和 length。

创建 tfrecord:

writer = tf.python_io.TFRecordWriter(filename + '_Squence.tfrecords')
example = tf.train.Example(features=tf.train.Features(
    feature={
        'vehicleid': tf.train.Feature(int64_list=tf.train.Int64List(value=[vehicleid])),
        'length': tf.train.Feature(int64_list=tf.train.Int64List(value=[length]))

    }))
writer.write(example.SerializeToString())
writer.close()

读取 tfrecords:

filepath = filename + "_Squence.tfrecords"
filename_queue = tf.train.string_input_producer([filepath])
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)   # return filename and file
features = tf.parse_single_example(serialized_example, features={
    'vehicleid': tf.FixedLenFeature([], tf.int64),
    'length': tf.FixedLenFeature([], tf.int64)
    })

vehicleid = tf.cast(features["vehicleid"], tf.int64)
length = tf.cast(features["length"], tf.int64)
return vehicleid, length

但是当我调试代码时,我会丢失一些数据。 例如,如果我发送这两个示例

[vehicleid=a, frameid=b], [vehicleid=c, frameid=d]

进入tfrecords文件,当我读取数据时,我会得到这样的数据

[车辆标识=a,框架标识=d]。

我丢失了一些数据。

有人可以帮我解决这个问题吗?非常感谢。

【问题讨论】:

    标签: python numpy machine-learning tensorflow reshape


    【解决方案1】:

    tf.train.string_input_producer([filepath]) 返回一个队列。每次您使用reader.read(filename_queue) 访问时,它都会返回队列的最后一个第一个元素。如果您第二次执行reader.read,它将返回第二个元素。

    如果你想达到一批元素,你可以使用tf.train.batch和队列的输出作为tf.train.batch.的输入

    【讨论】:

      猜你喜欢
      • 2018-04-17
      • 2021-10-19
      • 1970-01-01
      • 2011-08-20
      • 2021-03-13
      • 1970-01-01
      • 2021-05-25
      • 2019-10-18
      • 1970-01-01
      相关资源
      最近更新 更多