首页 > 解决方案 > UNET : DSC 和 IOU 用于分段

问题描述

我一直在尝试使用二元交叉熵作为损失来训练 UNET,并在训练和验证期间读取dice_coeffiou作为指标。5个epoch后的结果是

Epoch 5/5 2373/2373 [==============================] - 84s 35ms/step - loss: 0.0260 - dice_coef: 0.9864 - iou: 0.9734 - val_loss: 0.0579 - val_dice_coef: 0.9583 - val_iou: 0.9216

我使用的指标在这里:

def iou(y_true, y_pred):
  def f(y_true, y_pred):
    intersection = (y_true * y_pred).sum()
    union = y_true.sum() + y_pred.sum() - intersection
    x = (intersection + 1e-15) / (union + 1e-15)
    x = x.astype(np.float32)
    return x
return tf.numpy_function(f, [y_true, y_pred], tf.float32)

smooth = 1e-15
def dice_coef(y_true, y_pred):
    y_true = tf.keras.layers.Flatten()(y_true)
    y_pred = tf.keras.layers.Flatten()(y_pred)
    intersection = tf.reduce_sum(y_true * y_pred)
    return (2. * intersection + smooth) / (tf.reduce_sum(y_true) + tf.reduce_sum(y_pred) + smooth)

def dice_loss(y_true, y_pred):
    return 1.0 - dice_coef(y_true, y_pred)

评测结果在这里

46/46 [==============================] - 12s 259ms/step - loss: 0.0557 - dice_coef: 0.9567 - iou: 0.9181

我的疑问是

  1. 即使我得到了 95% 的 dice 和 91% 的 iou,但预测的掩码并不像预期的那样。他们为大多数图像预测了很多区域。我想知道这 95% 是如何获得的。有许多图像的预测不合理。
  2. 据我所知,训练和验证结果给出了一个平均骰子分数。预测的掩码将具有 [0,1] 之间的值。论文中通常会报道什么?是在应用阈值> 0.5 之后还是在阈值之前?我们不能用一个也需要阈值的指标来训练网络吗?如果是,请帮助我提供代码。评估模型后的测试图像结果如下:

预测和基本事实

标签: pythontensorflowkerasdeep-learningimage-segmentation

解决方案


如果要考虑阈值,则需要绘制ROC 曲线。对于二元分类(每像素),ROC 曲线显示准确度和特异性如何随阈值变化。
一旦你有了 ROC 曲线,你就可以测量“曲线下的面积”来获得一个评估分类器的数字。

您可以使用sklearn.metrics.roc_curve实现来计算它。


推荐阅读