Open luciaL opened 7 years ago
model.compile(... , sample_weight_mode="temporal")
You can calculate class weights with sklearn.utils.class_weight.compute_class_weight. Just make sure to flatten N-dim array.
Then if you have 4 classes you should create this kind of matrix:
class_weights = np.zeros((224,224, 4))
class_weights[:,:, 0] += 0.25
class_weights[:,:, 1] += 4
class_weights[:,:, 2] += 2
class_weights[:,:, 3] += 6
And finally:
model.fit(... , class_weight=class_weights)
Note, that it has been taken from keras's github. Works for me.
Thank you so much.I will try it.
Thanks @szymko1995 for this. I'm struggling with the logic behind this. Can you help me here?
Okay. So, when you have 4 classes, that you want to segment output matrix of NN will be WxHxN_classes. You set calculated weights (by for example sklearn.utils.class_weight.compute_class_weight) and paste them into each of 3-axis's WxH matrices. This way of setting weights for segmentation NN has been proposed by someone on StackOverflow or keras' GitHub as the output of segCNN isn't typical. Idk if API in Keras for this kind of NN has changed over a time, but I think it should work.
Thank you so much for you sharing.It really helps me a lot.Here is Another question. If I have two classes,how should I set the class weighting? Looking forward to your answer. Thank you so much .