Torch7 使用不平衡训练集的权重

Torch7 using weights with unbalanced training sets

我在我的卷积网络中使用 CrossEntropyCriterion。我有 150 个 classes,每个 class 的训练文件数量 非常不平衡(5 到 2000 个文件) .根据文档,我可以使用权重对此进行补偿:

criterion = nn.CrossEntropyCriterion([weights])

"If provided, the optional argument weights should be a 1D Tensor assigning weight to each of the classes. This is particularly useful when you have an unbalanced training set."

权重应该采用什么格式?例如:训练文件数 class n / 训练文件总数。

我假设你想在这个意义上平衡你的训练,小 class 变得更重要。通常 有无限多种可能的权重 会导致不同的结果。最简单的方法之一,它简单地假设每个 class 应该同等重要(因此有效地放弃经验先验)是将权重与

成比例
1 / # samples_in_class

例如

weight_of_class_y = # all_samples / # samples_in_y

这样,如果你有 5:2000 比例失调,较小的 class 对模型来说变得重要 400 倍。