1414from collections .abc import Callable
1515
1616import torch
17- from monai .metrics .regression import RegressionMetric
18- from monai .utils import MetricReduction
17+ from monai .metrics .metric import Metric
1918
2019
21- class MMD ( RegressionMetric ):
20+ class MMDMetric ( Metric ):
2221 """
2322 Unbiased Maximum Mean Discrepancy (MMD) is a kernel-based method for measuring the similarity between two
2423 distributions. It is a non-negative metric where a smaller value indicates a closer match between the two
@@ -31,29 +30,15 @@ class MMD(RegressionMetric):
3130 filter, but it can be any function that takes a tensor as input and returns a tensor as output such as a
3231 feature extractor or an Identity function.
3332 y_pred_transform: Callable to transform the y_pred tensor before computing the metric.
34- reduction: define mode of reduction to the metrics, will only apply reduction on `not-nan` values, available
35- reduction modes: {``"none"``, ``"mean"``, ``"sum"``, ``"mean_batch"``, ``"sum_batch"``, ``"mean_channel"``,
36- `"sum_channel"``}, default to ``"mean"``. if "none", will not do reduction. This parameter is ignored due to
37- the mathematical formulation of MMD.
38- get_not_nans: whether to return the `not_nans` count, if True, aggregate() returns (metric, not_nans). Here
39- `not_nans` count the number of not nans for the metric, thus its shape equals to the shape of the metric.
40- This parameter is ignored due to the mathematical formulation of MMD.
41-
4233 """
4334
44- def __init__ (
45- self ,
46- y_transform : Callable | None = None ,
47- y_pred_transform : Callable | None = None ,
48- reduction : MetricReduction | str = MetricReduction .MEAN ,
49- get_not_nans : bool = False ,
50- ) -> None :
51- super ().__init__ (reduction = reduction , get_not_nans = get_not_nans )
35+ def __init__ (self , y_transform : Callable | None = None , y_pred_transform : Callable | None = None ) -> None :
36+ super ().__init__ ()
5237
5338 self .y_transform = y_transform
5439 self .y_pred_transform = y_pred_transform
5540
56- def _compute_metric (self , y : torch .Tensor , y_pred : torch .Tensor ) -> torch .Tensor :
41+ def __call__ (self , y : torch .Tensor , y_pred : torch .Tensor ) -> torch .Tensor :
5742 """
5843 Args:
5944 y: first sample (e.g., the reference image). Its shape is (B,C,W,H) for 2D data and (B,C,W,H,D) for 3D.
0 commit comments