mindspore.train.MeanSurfaceDistance

class mindspore.train.MeanSurfaceDistance(symmetric=False, distance_metric='euclidean')[source]

Computes the Average Surface Distance from y_pred to y under the default setting. It measures how much, on average, the surface varies between the segmentation and the GT (ground truth).

Given two sets A and B, S(A) denotes the set of surface voxels of A, the shortest distance of an arbitrary voxel v to S(A) is defined as:

dis(v,S(A))=min sAS(A)vsA

The Average Surface Distance from set(B) to set(A) is given by:

AvgSurDis(BA)=sBS(B)dis(sB,S(A))|S(B)|

Where the ||*|| denotes a distance measure. |*| denotes the number of elements.

The mean of surface distance from set(B) to set(A) and from set(A) to set(B) is:

MeanSurDis(AB)=sAS(A)dis(sA,S(B))+sBS(B)dis(sB,S(A))|S(A)|+|S(B)|
Parameters
  • distance_metric (string) – Three measurement methods are supported: "euclidean" (Euclidean Distance) , "chessboard" (Chessboard Distance, Chebyshev Distance) or "taxicab" (Taxicab Distance, Manhattan Distance) Default: "euclidean" .

  • symmetric (bool) – Whether to calculate the Mean Surface Distance between y_pred and y. If False, it only calculates AvgSurDis(y_predy), otherwise, the mean of distance from y_pred to y and from y to y_pred, i.e. MeanSurDis(y_predy), will be returned. Default: False .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindspore.train import MeanSurfaceDistance
>>> x = Tensor(np.array([[3, 0, 1], [1, 3, 0], [1, 0, 2]]))
>>> y = Tensor(np.array([[0, 2, 1], [1, 2, 1], [0, 0, 1]]))
>>> metric = MeanSurfaceDistance(symmetric=False, distance_metric="euclidean")
>>> metric.clear()
>>> metric.update(x, y, 0)
>>> mean_average_distance = metric.eval()
>>> print(mean_average_distance)
0.8047378541243649
clear()[source]

Clears the internal evaluation result.

eval()[source]

Calculate mean surface distance.

Returns

numpy.float64. The mean surface distance value.

Raises

RuntimeError – If the update method is not called first, an error will be reported.

update(*inputs)[source]

Updates the internal evaluation result 'y_pred', 'y' and 'label_idx'.

Parameters

inputs – Input 'y_pred', 'y' and 'label_idx'. 'y_pred' and 'y' are a Tensor, list or numpy.ndarray. 'y_pred' is the predicted binary image. 'y' is the actual binary image. 'label_idx', the data type of label_idx is int.

Raises
  • ValueError – If the number of the inputs is not 3.

  • TypeError – If the data type of label_idx is not int or float.

  • ValueError – If the value of label_idx is not in y_pred or y.

  • ValueError – If y_pred and y have different shapes.