首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查TFRecordReader条目而不启动会话

检查TFRecordReader条目而不启动会话
EN

Stack Overflow用户
提问于 2016-10-17 17:05:35
回答 1查看 562关注 0票数 2

让我们假设我用MNIST示例(records.py)编写了一个records.py文件,如下所示:

代码语言:javascript
复制
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)中的一个记录。

代码语言:javascript
复制
    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的转储

代码语言:javascript
复制
?
?
    image_raw?
?
?&00>a?????????????(??Y??aC\?z??;??\????\e?\i???
                                                ??)L???^
?y????~??a???4??G??<????.M???n???t????VBљ?<???اZ???\?????,I?ņ

depth


label


width


height
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-17 18:00:08

tf.train.Example.ParseFromString()可用于将字符串转换为protobuf对象:

代码语言:javascript
复制
r = ...  # String object from `tf.python_io.tf_record_iterator()`.
example_proto = tf.train.Example()
example_proto.ParseFromString(r)

此协议缓冲区的架构可在tensorflow/core/example/example.proto中找到。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40091967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档