如何在Keras中使用fit_generator()加权类? [英] How to weight classes using fit_generator() in Keras?
问题描述
我正在尝试使用keras来拟合CNN模型以对图像进行分类.数据集具有来自某些类别的更多图像,因此其不平衡.
I am trying to use keras to fit a CNN model to classify images. The data set has much more images form certain classes, so its unbalanced.
我在Keras中读到了关于如何权衡损失以解决这一问题的另一件事,例如: https://datascience.stackexchange.com/Questions/13490/如何为喀拉斯中的不平衡类设置权重,对此进行了很好的解释.但是,它总是解释 fit ()函数,而不是 fit_generator ()函数.
I read different thing on how to weight the loss to account for this in Keras, e.g.: https://datascience.stackexchange.com/questions/13490/how-to-set-class-weights-for-imbalanced-classes-in-keras, which is nicely explained. But, its always explaining for the fit() function, not the fit_generator() one.
实际上,在fit_generator()函数中,我们没有' class_weights '参数,但是我们有' weighted_metrics ',我不理解其描述:"weighted_metrics:在训练和测试期间要通过sample_weight或class_weight评估和加权的指标列表."
Indeed, in the fit_generator() function we dont have the 'class_weights' parameter, but instead we have 'weighted_metrics', which I dont understand its description: "weighted_metrics: List of metrics to be evaluated and weighted by sample_weight or class_weight during training and testing."
如何从"class_weights"传递到"weighted_metrics"?有人能举一个简单的例子吗?
How can I pass from 'class_weights' to 'weighted_metrics'? Would any one have a simple example?