Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.train.HausdorffDistance

class mindspore.train.HausdorffDistance(distance_metric='euclidean', percentile=None, directed=False, crop=True)[source]

Calculates the Hausdorff distance. Hausdorff distance is the maximum and minimum distance between two point sets. Given two feature sets A and B, the Hausdorff distance between two point sets A and B is defined as follows:

H(A,B)=max[h(A,B),h(B,A)]h(A,B)=maxaA{minbBab}h(B,A)=maxbB{minaAba}

where h(A,B) is the maximum distance of a set A to the nearest point in the set B, h(B,A) is the maximum distance of a set B to the nearest point in the set A. The distance calculation is oriented, which means that most of times h(A,B) is not equal to h(B,A). H(A,B) is the two-way Hausdorff distance.

Parameters
  • distance_metric (string) – Three distance measurement methods are supported: "euclidean" (Euclidean Distance) , "chessboard" (Chessboard Distance, Chebyshev Distance) or "taxicab" (Taxicab Distance, Manhattan Distance). Default: "euclidean" .

  • percentile (float) – Floating point numbers between 0 and 100. Specify the percentile parameter to get the percentile of the Hausdorff distance. Default: None .

  • directed (bool) – If True, it only calculates h(y_pred, y) distance, otherwise, max(h(y_pred, y), h(y, y_pred)) will be returned. Default: False .

  • crop (bool) – Crop input images and only keep the foregrounds. In order to maintain two inputs' shapes, here the bounding box is achieved by (y_pred | y) which represents the union set of two images. Default: True .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindspore.train import HausdorffDistance
>>>
>>> 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 = HausdorffDistance()
>>> metric.clear()
>>> metric.update(x, y, 0)
>>> mean_average_distance = metric.eval()
>>> print(mean_average_distance)
1.4142135623730951
clear()[source]

Clears the internal evaluation result.

eval()[source]

Calculate the no-directed or directed Hausdorff distance.

Returns

numpy.float64, the hausdorff distance.

Raises

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

update(*inputs)[source]

Updates the internal evaluation result with the inputs: '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. Data type of 'label_idx' is int or float.

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.