0bserver07 / One-Hundred-Layers-Tiramisu

Keras Implementation of The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation by (Simon Jégou, Michal Drozdzal, David Vazquez, Adriana Romero, Yoshua Bengio)
https://arxiv.org/abs/1611.09326
MIT License
197 stars 54 forks source link

If I have two classes,how should I set the class weighting? #12

Open luciaL opened 7 years ago

luciaL commented 7 years ago

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 .

szkocot commented 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.

luciaL commented 7 years ago

Thank you so much.I will try it.

deepitapai commented 6 years ago

Thanks @szymko1995 for this. I'm struggling with the logic behind this. Can you help me here?

szkocot commented 6 years ago

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.