如何在Keras中输入遮罩?

时间:2020-05-20 08:12:18

标签: python tensorflow github keras

我要使用此Surface Distance Based Metrics 代码是

import surface_distance as surfdist

surface_distances = surfdist.compute_surface_distances(
    mask_gt, mask_pred, spacing_mm=(1.0, 1.0, 1.0))
hd_dist_95 = surfdist.compute_robust_hausdorff(surface_distances, 95)

如何输入mask_gt和mask_pred?我试图以这种方式做到这一点,

import surface_distance as surfdist

def hausdorff_distance(y_true, y_pred):

  surface_distances = surfdist.compute_surface_distances(
          y_true, y_pred, spacing_mm=(1.0, 1.0, 1.0))
  hd_dist_95 = surfdist.compute_robust_hausdorff(surface_distances, 95)
  return hd_dist_95

但返回

TypeError: Input 'x' of 'LogicalOr' Op has type float32 that does not match expected type of bool.

1 个答案:

答案 0 :(得分:0)

听起来像您的损失函数希望获得布尔张量,而您的gt张量是“ float”类型(可能是一些值为0,1?的数组)。尝试将张量转换为布尔值,例如:

tf.keras.backend.cast(y_true, 'bool')