Kaggle空中客车船舶检测挑战。如何应对班级失衡?

时间:2018-09-28 14:15:43

标签: python keras artificial-intelligence conv-neural-network kaggle

我的模型总是针对所有像素在0.5的概率下预测。
我放下了所有没有船只的图像,并尝试了焦距损失,损失,加权损失以应对不平衡。
但是结果是一样的。几批次之后,我预测的遮罩逐渐变为全零。
这是我的笔记本:enter link description here Kaggle讨论:enter link description here

在笔记本中,基本上我所做的是:
(1)在没有船的情况下丢弃所有样品
(2)建立简单的U型网络
(3)定义三个自定义损失函数(iouloss,focal_binarycrossentropy,biased_crossentropy),所有这些我都尝试过。
(4)培训并提交

#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)

2 个答案:

答案 0 :(得分:0)

Keras提供的一个选项是documentationclass_weight中的fit参数:

  

class_weight:可选的词典映射类索引(整数)到权重(浮点)值,用于对损失函数加权(仅在训练过程中)。这可能有助于告诉模型“更多关注”来自代表性不足的类的样本。

这将使您在某种程度上抵消不平衡。

答案 1 :(得分:0)

我听说过使用Dice coefficient来解决此问题,尽管我没有这样做的个人经验。也许您可以尝试一下?它与Jaccard有关,但有传闻说它更容易训练。很抱歉不提供更多具体信息。