如何检查 Tensorflow .tfrecord 文件? [英] How to inspect a Tensorflow .tfrecord file?

查看:37
本文介绍了如何检查 Tensorflow .tfrecord 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .tfrecord 但我不知道它的结构.如何检查架构以了解 .tfrecord 文件包含的内容?

I have a .tfrecord but I don't know how it is structured. How can I inspect the schema to understand what the .tfrecord file contains?

所有 Stackoverflow 答案或文档似乎都假设我知道文件的结构.

All Stackoverflow answers or documentation seem to assume I know the structure of the file.

reader = tf.TFRecordReader()
file = tf.train.string_input_producer("record.tfrecord")
_, serialized_record = reader.read(file)

...HOW TO INSPECT serialized_record...

推荐答案

找到了!

import tensorflow as tf

for example in tf.python_io.tf_record_iterator("data/foobar.tfrecord"):
    print(tf.train.Example.FromString(example))

您还可以添加:

from google.protobuf.json_format import MessageToJson
...
jsonMessage = MessageToJson(tf.train.Example.FromString(example))

这篇关于如何检查 Tensorflow .tfrecord 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆