【问题标题】:How to measure dice coefficient of two images如何测量两个图像的骰子系数
【发布时间】:2021-09-09 02:50:05
【问题描述】:

我有两个相同的 RGB 图像并尝试找到骰子系数。我希望结果是 1.0,但实际上是 0.0039。

我做错了什么??

from skimage.io import imread

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

im=imread(r'C:\Users\User\Desktop\Examine_unet_CAMvid\imga.png')
print(dice_coef(im,im))

【问题讨论】:

  • 或者代替np.sum,使用np.count_nonzero
  • Bilal 的值是 uint8 。无论如何感谢您的建议`

标签: python image-processing computer-vision metrics scikit-image


【解决方案1】:

试试这个:

from keras import backend as K
def dice_coef(y_true, y_pred):
  smooth=1
  intersection = K.sum(y_true * y_pred, axis=[1,2,3])
  union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3])
  return = K.mean((2. * intersection + smooth)/(union + smooth), axis=0)

【讨论】:

  • ValueError: 3 维输入的缩减维度 3 无效。对于具有输入形状的“Sum”(操作:“Sum”):[320,320,3],[3] 和计算的输入张量:input[1] = 。
  • y_true 和 y_pred 的形状是什么?看看这个github.com/keras-team/keras/issues/3611
猜你喜欢
  • 2022-09-24
  • 2018-09-20
  • 2021-07-07
  • 2018-04-14
  • 2018-04-15
  • 1970-01-01
  • 2014-03-16
  • 2016-05-02
  • 2021-03-04
相关资源
最近更新 更多