代码

def parse_fn(example):
    features_dict = {}
    features_dict['label'] = tf.FixedLenFeature([1], tf.float32)
    for group_name in group_id_counts_dict.keys():
        features_dict[group_name] = tf.VarLenFeature(tf.int64)
    features = tf.parse_example(example, features=features_dict)
    return features

dataset = tf.data.TFRecordDataset(files, num_parallel_reads=32).map(parse_fn)

dataset = dataset.apply(tf.data.experimental.shuffle_and_repeat(10000, 3))

错误

ValueError: Shape must be rank 1 but is rank 0 for 'ParseExample/ParseExample' (op: 'ParseExample') with input shapes

原因

features = tf.parse_example(example, features=features_dict)
改为:
features = tf.parse_single_example(example, features=features_dict)