我有一个CNN模型,每个训练样例都有N个分类标签,我正在尝试从我的数据集创建TFRecords,这些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())
在阅读方面,我正在做类似以下的事情。我假设有一定数量的标签(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']
当我尝试这个Tensorflow报告时:
ValueError: Cannot reshape a tensor with 1 elements to shape [4] (4 elements)
显然,我不理解一些相当基本的东西
答案 0 :(得分:2)
尝试设置默认值= [-1] * 4