我正在处理多类语义分割任务,并且想定义一个自定义的加权指标来计算我的神经网络的性能。
我正在使用 U-net 将图像分割成 8 个类别之一,其中 1-7 是特定类别,0 是背景。如何使用 Keras metrics 上定义的标准自定义指标模板页面,以便我只得到 channel 1-7 的 IoU,乘以 (1,7) 权重数组?我尝试使用
删除自定义指标中的背景 channely_true, y_pred = y_true[1:,:,:], y_pred[1:, :,:]
但看起来这不是我想要的。任何帮助将不胜感激。
最佳答案
必要的改变
def dice_coef_multilabel(y_true, y_pred, numLabels=CLASSES):
dice=0
for index in range(numLabels):
dice -= dice_coef(y_true[:,:,index], y_pred[:,:,index])
return dice
如果需要,可以通过使用两个嵌套循环遍历所有 channel 组合来跨 channel 计算骰子系数。我还包括骰子系数计算。
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)
FWIW,this github link有各种类型的指标以 channel 方式实现。
关于python-3.x - 语义分割的自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57786303/