python - 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)
解决方案
我听说过使用骰子系数来解决这个问题,尽管我没有这样做的个人经验。也许你可以试试这个?它与 Jaccard 有关,但听说它更容易训练。很抱歉没有提供更具体的内容。
推荐阅读
- python - 连续训练多个 TensorFlow 模型:如何确保会话清晰?
- javascript - 有没有办法让firestore实时监听器在客户端或服务器端持久化?
- c++ - 日期验证在 C++ 中不一致
- powershell - 使用 Invoke-WebRequest 下载 pem 文件
- sql - 如何对从 1 到 n 次出现的次数进行排序
- github - 使用 GitHub 操作构建解决方案
- nuget - Nuget:此包已签名,但不是由受信任的签名者签名
- flutter - 有什么方法可以访问转换为 Uint8List 的视频文件路径
- cytoscape - Cytoscape 3.7 和 3.8 版本之间的节点度分布不一致
- android-studio - 什么时候在 setOnClickListener 上写 inside () 或 {}?安卓工作室