首页 > 解决方案 > Kaggle空客船舶检测挑战。如何处理类不平衡?

问题描述

我的模型总是预测所有像素的概率低于 0.5。
我放弃了所有没有船只的图像,并尝试了焦点损失、iou 损失、加权损失来处理不平衡。
但结果是一样的。经过几批后,我预测的掩码逐渐变为全零。
这是我的笔记本:在此处输入链接描述 Kaggle 讨论:在此处输入链接描述

在 notebook 中,基本上我所做的是:
(1)丢弃所有没有船的样本
(2)构建一个普通的 u-net
(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)

标签: pythonkerasartificial-intelligenceconv-neural-networkkaggle

解决方案


我听说过使用骰子系数来解决这个问题,尽管我没有这样做的个人经验。也许你可以试试这个?它与 Jaccard 有关,但听说它更容易训练。很抱歉没有提供更具体的内容。


推荐阅读