Python 在不启动会话的情况下检查TFRecordReader条目
假设我用MNIST示例()编写了一个TFRecords文件 这是这样做的:Python 在不启动会话的情况下检查TFRecordReader条目,python,tensorflow,Python,Tensorflow,假设我用MNIST示例()编写了一个TFRecords文件 这是这样做的: 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': _i
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\u iter=tf.python\u io.tf\u record\u迭代器(db\u path)
例如,可以使用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
?
?
原图?
?
&00>a???????(Y??aC \?z;??\e?\i???
我^
可以使用tf.train.Example.ParseFromString()
将字符串转换为protobuf对象:
r = ... # String object from `tf.python_io.tf_record_iterator()`.
example_proto = tf.train.Example()
example_proto.ParseFromString(r)
可以在中找到此协议缓冲区的架构。谢谢,不知道为什么找不到它。
r = ... # String object from `tf.python_io.tf_record_iterator()`.
example_proto = tf.train.Example()
example_proto.ParseFromString(r)