3

I use the latest version of deeplab(v3+) to train my own dataset consisting of 6 classes. I am able to train my dataset but as my labels are strongly imbalanced I would like to weight each class with a class specific value.

Here is how I realized this with my SegNet

loss_weight = np.array([0.975644, 1.025603, 0.601745, 6.600600, 1.328684, 0.454776])    

cross_entropy = -tf.reduce_sum(tf.multiply(labels * tf.log(softmax + epsilon), head), axis=[1])

How would that work with deeplab net?

1 Answers1

2

According to this discussion, you do this on train_utils.py file as below,

irgore_weight = 0
label0_weight =1
label1_weight = 10
label2_weight = 15
not_ignore_mask = 
tf.to_float(tf.equal(scaled_labels, 0)) * label0_weight +
tf.to_float(tf.equal(scaled_labels, 1)) * label1_weight +
tf.to_float(tf.equal(scaled_labels, 2)) * label2_weight +
tf.to_float(tf.equal(scaled_labels, ignore_label)) * irgore_weight 
tf.losses.softmax_cross_entropy(
    one_hot_labels,
    tf.reshape(logits, shape=[-1, num_classes]),
    weights=not_ignore_mask,
    scope=loss_scope)

For more details please follow the link of the discussion provided earlier.

Sumsuddin Shojib
  • 3,583
  • 3
  • 26
  • 45