I have a highly unbalanced dataset and I want to use the class_weight = 'auto'
in the 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
.
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
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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.