【问题标题】:Reading a tfrecord: DecodeError: Error parsing message读取 tfrecord:DecodeError: Error parsing message
【发布时间】:2020-05-19 07:34:24
【问题描述】:

我正在使用 colab 在 tensorflow 排名上运行 tutorial。它使用 wget 来获取 tfrecord:

!wget -O "/tmp/train.tfrecords" "http://ciir.cs.umass.edu/downloads/Antique/tf-ranking/ELWC/train.tfrecords"

我正在使用这段代码来尝试查看 tfrecord 的结构:

for example in tf.compat.v1.python_io.tf_record_iterator("/tmp/train.tfrecords"):
    print(tf.train.Example.FromString(example))
    break

我得到:

DecodeError: Error parsing message

一般怎么看tfrecords的结构呢?

第二个问题:在哪里可以找到像 tf.train.Example 这样的类的文档?我刚找到这个empty page

【问题讨论】:

    标签: python tensorflow tensorflow-datasets


    【解决方案1】:

    问题的关键在于记录是使用另一个模式序列化的:ExampleListWithContext 模式,而不是基本的tf.train.Example 模式。更新正确的反序列化可以解决问题。

    filenames = ['/tmp/train.tfrecords']
    raw_dataset = tf.data.TFRecordDataset(filenames)
    for e in raw_dataset.take(1):
        ELWC = input_pb2.ExampleListWithContext()
        v = ELWC.FromString(e.numpy())
        print(v.context)
        for e in v.examples:
            print(e)
    

    输出:

    features {
      feature {
        key: "query"
        value {
          bytes_list {
            value: "why do ..."
          }
        }
      }
      feature {
        key: "query_bert_encoder_outputs"
        value {
          float_list {
    ...
    }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-29
      • 2021-03-13
      • 2013-05-27
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多