[英]class_weight='auto' for model.fit_generator keras
I have a highly unbalanced dataset and I want to use the class_weight = 'auto'
in the model.fit_generator
. 我有一个非常不平衡的数据集,我想用class_weight = 'auto'
的model.fit_generator
。 However, when I do that I see that my model does not learn: training_acc = 0.65
and val_acc = 0.64
starting from epoch 1 up to 50. If I set the class_weight = 'None'
then the model starts learning: training_acc = 0.92 and val_acc = 0.88 at epoch 50
. 但是,当我这样做时,我发现我的模型没有学习到: training_acc = 0.65
val_acc = 0.64
training_acc = 0.65
并且val_acc = 0.64
从第1 val_acc = 0.64
开始直到50。如果我设置class_weight = 'None'
那么该模型开始学习: training_acc = 0.92 and val_acc = 0.88 at epoch 50
。
Did anyone else face this problem? 还有其他人面对这个问题吗? Do I have to define a dictionary to my class weights manually? 我必须手动为班级重量定义字典吗?
For model.fit_generator
in keras you can use train_generator.classes
for the proper class names for your weighting 对于keras中的model.fit_generator
,您可以将train_generator.classes
用作权重的正确类名
Then you simple create a dictionary mapping your classes., eg 然后,您只需创建一个映射您的类的字典即可,例如
class_weights = {'wolf':30 , 'fox':18}
That gives classes 'wolf' weight 30 and 'fox' weight '18' 这样,“狼”的权重为30,“狐狸”的权重为“ 18”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.