python - UNET : DSC 和 IOU 用于分段
问题描述
我一直在尝试使用二元交叉熵作为损失来训练 UNET,并在训练和验证期间读取dice_coeff和iou作为指标。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
我的疑问是
- 即使我得到了 95% 的 dice 和 91% 的 iou,但预测的掩码并不像预期的那样。他们为大多数图像预测了很多区域。我想知道这 95% 是如何获得的。有许多图像的预测不合理。
- 据我所知,训练和验证结果给出了一个平均骰子分数。预测的掩码将具有 [0,1] 之间的值。论文中通常会报道什么?是在应用阈值> 0.5 之后还是在阈值之前?我们不能用一个也需要阈值的指标来训练网络吗?如果是,请帮助我提供代码。评估模型后的测试图像结果如下:
解决方案
如果要考虑阈值,则需要绘制ROC 曲线。对于二元分类(每像素),ROC 曲线显示准确度和特异性如何随阈值变化。
一旦你有了 ROC 曲线,你就可以测量“曲线下的面积”来获得一个评估分类器的数字。
您可以使用sklearn.metrics.roc_curve
实现来计算它。
推荐阅读
- r - 如何删除 data.table 的不均匀列中的重复值?
- oauth-2.0 - 在 JHipster 中使用 Keycloak 扩展用户实体
- javascript - 如何限制鼠标点击复选框并从JS触发?
- excel - 如何创建一个 VBA 函数,该函数将从 excel 中选择值并“可拖动”(即基于活动单元格将具有不同的输入)
- c# - 如何生成长度小于/大于长度的字符串
- android - 设备处于空闲模式时不调用位置结果回调
- ios - 使用 Braintree SDK 在 Paypal 结帐中添加运费
- opencv - 从 OpenCv 图像比较中获取比较分数
- java - 使用 java 8 查找列表中重复次数最多的短语
- node.js - 如何使用来自另一个集合的数据创建文档?