如何编写和检索列表的TFRecord功能?

bob*_*obw 6 tensorflow

我有一个CNN模型,每个训练示例需要N个分类标签,我正在尝试从我的数据集创建TFRecords,它具有标签功能,这是一个int64列表.

在碎片创建方面,我正在使用类似下面的内容.我已经将标签数据明确地放在代码中,但显然每个样本都会有所不同:

example = tf.train.Example(features=tf.train.Features(feature={
  ... # other stuff  
  'label': tf.train.Feature(
                  int64_list=tf.train.Int64List(value=[1, 2, 3, 4])}))
writer.write(example.SerializeToString())
Run Code Online (Sandbox Code Playgroud)

在阅读方面,我正在做类似以下的事情.我假设有固定数量的标签(4):

features = tf.parse_single_example(
      serialized_example,
      # Defaults are not specified since both keys are required.
      features={
        ... # other stuff
        'label': tf.FixedLenFeature(
            [4], dtype=tf.int64, default_value=-1)}
      )
label = features['label']
Run Code Online (Sandbox Code Playgroud)

当我尝试这个Tensorflow报告时:

ValueError: Cannot reshape a tensor with 1 elements to shape [4] (4 elements)
Run Code Online (Sandbox Code Playgroud)

显然,我不理解一些相当基本的东西

小智 3

尝试设置默认值= [-1]*4