【发布时间】:2018-12-06 14:23:03
【问题描述】:
我所有的训练图像都在 tfrecords 文件中。现在它们以这样的标准方式使用:
dataset = dataset.apply(tf.data.experimental.map_and_batch(
map_func=lambda x: preprocess(x, data_augmentation_options=data_augmentation),
batch_size=images_per_batch)
preprocess 返回解码后的图像和标签,它们都来自 tfrecord 文件。
现在是新情况。我还想要每个示例的样本权重。所以而不是
return image,label
在预处理中,应该是
return image, label, sample_weight
但是,这个 sample_weight 不在 tfrecord 文件中。它是在训练开始时根据每个类的示例数计算的。基本上它是一个 Python 字典 weights[label] = sample_weights。
问题是如何在 tf.data 管道中使用这些样本权重。因为 label 是一个张量,它不能用于索引 Python 字典。
【问题讨论】:
标签: python tensorflow tensorflow-datasets