mindspore.nn.RootMeanSquareDistance
- class mindspore.nn.RootMeanSquareDistance(symmetric=False, distance_metric='euclidean')[source]
Computes the Root Mean Square Surface Distance from y_pred to y under the default setting.
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:
\[{\text{dis}}\left (v, S(A)\right ) = \underset{s_{A} \in S(A)}{\text{min }}\rVert v - s_{A} \rVert\]The Root Mean Square Surface Distance from set(B) to set(A) is:
\[RmsSurDis(B \rightarrow A) = \sqrt{\frac{\sum_{s_{B} \in S(B)}^{} {\text{dis}^2 \left ( s_{B}, S(A) \right )} }{\left | S(B) \right |}}\]Where the ||*|| denotes a distance measure. |*| denotes the number of elements.
The Root Mean Square Surface Distance from set(B) to set(A) and from set(A) to set(B) is:
\[RmsSurDis(A \leftrightarrow B) = \sqrt{\frac{\sum_{s_{A} \in S(A)}^{} {\text{dis} \left ( s_{A}, S(B) \right ) ^{2}} + \sum_{s_{B} \in S(B)}^{} {\text{dis} \left ( s_{B}, S(A) \right ) ^{2}}}{\left | S(A) \right | + \left | S(B) \right |}}\]- Parameters
distance_metric (string) – Three measurement methods are supported: “euclidean”, “chessboard” or “taxicab”. Default: “euclidean”.
symmetric (bool) – Whether to calculate the symmetric average root mean square distance between y_pred and y. If False, only calculates \(RmsSurDis(y_{pred}, y)\) surface distance, otherwise, the mean of distance from y_pred to y and from y to y_pred, i.e. \(RmsSurDis({y\_pred} \leftrightarrow y)\) will be returned. Default: False.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import nn, Tensor >>> >>> 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 = nn.RootMeanSquareDistance(symmetric=False, distance_metric="euclidean") >>> metric.clear() >>> metric.update(x, y, 0) >>> root_mean_square_distance = metric.eval() >>> print(root_mean_square_distance) 1.0000000000000002
- eval()[source]
Calculate Root Mean Square Distance.
- Returns
numpy.float64, root mean square surface distance.
- 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 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.