【发布时间】: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