【问题标题】:Kaggle airbus ship detection challenge.How to deal with class imbalance?Kaggle空客船舶检测挑战。如何处理类不平衡?
【发布时间】:2019-03-04 13:34:09
【问题描述】:

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

在笔记本中,基本上我所做的是:
(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)

【问题讨论】:

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


    【解决方案1】:

    Keras 提供的一个选项是fit 中的class_weight 参数,来自documentation

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

    这会让你在一定程度上抵消这种不平衡。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2018-01-05
        • 2021-06-07
        • 1970-01-01
        • 2019-08-11
        • 2018-01-05
        • 1970-01-01
        • 2021-01-07
        • 2016-06-19
        • 2015-09-13
        相关资源
        最近更新 更多