-1

My model always predict under probability 0.5 for all pixels.
I dropped all images without ships and have tried focal loss,iou loss,weighted loss to deal with imbalance .
But the result is same.After few batches the masks i predicted gradually became all zeros.
Here is my notebook: enter link description here Kaggle discussion:enter link description here

In the notebook , basically what i did is :
(1)discard all samples where there is no ship
(2)build a plain u-net
(3)define three custom loss function(iouloss,focal_binarycrossentropy,biased_crossentropy), all of which i have tried.
(4)train and submit

#define different losses to try
def iouloss(y_true,y_pred):
    intersection = K.sum(y_true * y_pred, axis=-1)
    sum_ = K.sum(y_true + y_pred, axis=-1)
    jac = intersection / (sum_ - intersection)
    return 1 - jac
def focal_binarycrossentropy(y_true,y_pred):
    #focal loss with gamma 8
    t1=K.binary_crossentropy(y_true, y_pred)
    t2=tf.where(tf.equal(y_true,0),t1*(y_pred**8),t1*((1-y_pred)**8))
    return t2
def biased_crossentropy(y_true,y_pred):
    #apply 1000 times heavier punishment to ship pixels
    t1=K.binary_crossentropy(y_true, y_pred)
    t2=tf.where(tf.equal(y_true,0),t1*1000,t1)
    return t2
...
#try different loss function
unet.compile(loss=iouloss, optimizer="adam", metrics=[ioumetric])
or
unet.compile(loss=focal_binarycrossentropy, optimizer="adam", metrics=[ioumetric])
or
unet.compile(loss=biased_crossentropy, optimizer="adam", metrics=[ioumetric])
...
#start training
unet.train_on_batch(x=image_batch,y=mask_batch)
abracadabra
  • 371
  • 2
  • 16

2 Answers2

0

One option that Keras provides is class_weight parameter in fit from documentation:

class_weight: Optional dictionary mapping class indices (integers) to a weight (float) value, used for weighting the loss function (during training only). This can be useful to tell the model to "pay more attention" to samples from an under-represented class.

This will allow you to counter the imbalance to some extent.

nuric
  • 11,027
  • 3
  • 27
  • 42
0

I have heard use of the Dice coefficient for this problem, although I have no personal experience of having done so. Perhaps you could try this? It is related to the Jaccard but have heard anecdotally that it is easier to train. Sorry not to offer anything more concrete.

jmsinusa
  • 1,584
  • 1
  • 13
  • 21