首页 > 解决方案 > 骰子系数大于 1

问题描述

我正在使用 UNET 从图像中分割人。我正在使用 COCO 数据集来做同样的事情。以下是我使用 tensorflow 训练模型时使用的损失定义。

smooth = 1.

def dice_coef(y_true, y_pred):
    y_true_f = K.flatten(y_true)
    y_pred_f = K.flatten(y_pred)
    intersection = K.sum(y_true_f * y_pred_f)
    return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)


def dice_coef_loss(y_true, y_pred):
    return -dice_coef(y_true, y_pred)

def iou(y_true, y_pred, smooth=1.):
    intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
    union = K.sum(y_true,-1) + K.sum(y_pred,-1) - intersection
    iou = (intersection + smooth) / ( union + smooth)
    return iou

我在这里找到了 dice 和 dice loss 的实现。

model.compile(optimizer=Adam(lr=lr), loss=dice_coef_loss,
                                metrics=[dice_coef, iou])

批量大小为 8,学习率为 1e-4,我在第一个时期得到以下结果

以下是日志结果: 请解释一下为什么骰子系数大于 1。

纪元 1/100

2687/8014 [=========>........] - ETA:3:04:59 - 损失:-1.0958 - dice_coef : 1.0957 - 借: 0.5446

标签: tensorflowkerasunity3d-unet

解决方案


确保你标准化the images并且the masks

归一化图像和掩码意味着它们的像素值介于01

我有同样的问题,原因是我没有规范化面具


推荐阅读