Tensorflow:有没有办法将元数据保存在 TFRecords 文件中

kri*_*nab 5 python tensorflow

有没有办法在文件创建时将数据集元数据保存在 Tensorflow TFRecords 文件中?

我一直在看新Tensorflow Datasets包装,它真的很不错。他们做了很多很好的工作来简化将标准数据集放入 tensorflow 训练管道的过程。

这个工具的一个很好的特性是它保存了关于数据集的元数据,例如数据集中的示例数量,或训练和测试拆分中的样本等。该DatasetInfo()对象将在内存中保存数据集的元数据。这是从该包的 github 存储库中获取的示例:

    tfds.core.DatasetInfo(
        name='mnist',
        version=1.0.0,
        description='The MNIST database of handwritten digits.',
        urls=[u'http://yann.lecun.com/exdb/mnist/'],
        features=FeaturesDict({
            'image': Image(shape=(28, 28, 1), dtype=tf.uint8),
            'label': ClassLabel(shape=(), dtype=tf.int64, num_classes=10)
        },
        total_num_examples=70000,
        splits={
            u'test': <tfds.core.SplitInfo num_examples=10000>,
            u'train': <tfds.core.SplitInfo num_examples=60000>
        },
        supervised_keys=(u'image', u'label'),
        citation='"""
            @article{lecun2010mnist,
              title={MNIST handwritten digit database},
              author={LeCun, Yann and Cortes, Corinna and Burges, CJ},
              journal={ATT Labs [Online]. Available: http://yann. lecun. com/exdb/mnist},
              volume={2},
              year={2010}
            }
      """',
  )
Run Code Online (Sandbox Code Playgroud)

现在,如果您查看此对象,您会发现它包含 aFeaturesDict和其他对象,当将 TFRecords 文件摄取到 Tensorflow 时,我们通常会将这些对象传递给解析函数。

因此我想知道是否有办法在文件编码时将这种类型的元数据保存到 TFRecords 文件中?否则,用户必须遍历整个数据集才能获得简单的信息,例如示例数量。在计算要运行的步骤数等时,此类信息很重要。