让我们假设我用MNIST示例(records.py)编写了一个records.py文件,如下所示:
writer = tf.python_io.TFRecordWriter(filename)
for index in range(num_examples):
image_raw = images[index].tostring()
example = tf.train.Example(features=tf.train.Features(feature={
'height': _int64_feature(rows),
'width': _int64_feature(cols),
'depth': _int64_feature(depth),
'label': _int64_feature(int(labels[index])),
'image_raw': _bytes_feature(image_raw)}))
writer.write(example.SerializeToString())
writer.close()然后在其他脚本中加载它。但我发现的唯一方法是将其作为张量运行并提取数据,其中r是迭代器record_iter = tf.python_io.tf_record_iterator(db_path)中的一个记录。
with tf.Session() as sess_tmp:
single_ex = (sess_tmp.run(tf.parse_single_example(r,features={
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'depth': tf.FixedLenFeature([], tf.int64),
'image_raw': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([], tf.int64),
})))例如,可以使用single_ex['height']检索数据。然而,在我看来,必须有更简单的办法。我似乎找不到相应的.proto来检索数据。数据肯定在那里。下面是r的转储
?
?
image_raw?
?
?&00>a?????????????(??Y??aC\?z??;??\????\e?\i???
??)L???^
?y????~??a???4??G??<????.M???n???t????VBљ?<???اZ???\?????,I?ņ
depth
label
width
height发布于 2016-10-17 18:00:08
tf.train.Example.ParseFromString()可用于将字符串转换为protobuf对象:
r = ... # String object from `tf.python_io.tf_record_iterator()`.
example_proto = tf.train.Example()
example_proto.ParseFromString(r)此协议缓冲区的架构可在tensorflow/core/example/example.proto中找到。
https://stackoverflow.com/questions/40091967
复制相似问题