多类数据集不平衡

时间:2020-02-05 19:49:27

标签: keras tensorflow2.0 tensorflow-datasets

point.copy(vertex1);
point.applyMatrix4(plane.matrixWorld)
sphereCalc.containsPoint(point);

point.copy(vertex2);
point.applyMatrix4(plane.matrixWorld)
sphereCalc.containsPoint(point);

// ... and so on

我在实现准确性方面存在问题,我正在训练9个类别的数据集,其中类别1、4和5仅具有100、96、90个图像,而其余类别具有500个以上的图像。因此,由于权重偏向数量更多的图像,因此我无法获得更高的精度。我希望在训练期间所有类都被认为相等,即500。如果我可以通过tensorflow或任何keras函数代码对类进行上采样,将不胜感激。而不是手动对文件夹中的图像进行上采样或下采样。<​​/ p>

1 个答案:

答案 0 :(得分:1)

您可以在fit方法中使用class_weight参数。 对于上采样,这是不可避免的,需要大量的手工工作。

假设您有一个形状为(anything, 9)的输出,并且您知道每个类的总计:

totals = np.array([500,100,500,500,96,90,.......])
totalMean = totals.mean()
weights = {i: totalMean / count for i, count in enumerate(totals)]

model.fit(....., class_weight = weights)