python-3.x - 语义分割的自定义指标

标签 python-3.x tensorflow keras

我正在处理多类语义分割任务,并且想定义一个自定义的加权指标来计算我的神经网络的性能。

我正在使用 U-net 将图像分割成 8 个类别之一,其中 1-7 是特定类别,0 是背景。如何使用 Keras metrics 上定义的标准自定义指标模板页面,以便我只得到 channel 1-7 的 IoU,乘以 (1,7) 权重数组?我尝试使用

删除自定义指标中的背景 channel
y_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/

相关文章:

machine-learning - 为什么预习完成后,转移学习会导致错误/丢失从随机重新开始?

Keras LSTM 时间分布式,有状态

python-3.x - 函数不起作用、语法错误等等

python - 如何在 tkinter python 中的按钮小部件的命令属性中使用 lambda 表达式调用回调函数

python - 从字典列表中动态创建嵌套 json 对象

python - 生成一个新的 pandas Dataframe,由唯一的 userID 和其他列中的模式组成

python - Keras 使用 tf.data.Dataset 预测循环内存泄漏,但不使用 numpy 数组

python-3.x - 如何在没有 PIL 或 Pillow 的情况下在 Canvas 上旋转图像(由 PhotoImage 类加载)?

java - 在 GPU Java 上配置 Tensorflow

python - 具有不同形状的 Tensorflow 数据集