MetricsReloaded icon indicating copy to clipboard operation
MetricsReloaded copied to clipboard

BinaryPairwiseMeasures.__init__() got an unexpected keyword argument 'axis'

Open ibowennn opened this issue 4 months ago • 0 comments

When I ran the example in MONAI, I encountered this error. MONAI version 1.3.2 MetricsReloaded version 0.1.0 The example code is as follows:

import torch
from monai.metrics import MetricsReloadedBinary

metric_name = "Cohens Kappa"
metric = MetricsReloadedBinary(metric_name=metric_name)

y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 1.0]]]])
y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])
print(metric(y_pred, y))

y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 0.0]]]])
y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])
print(metric(y_pred, y))

print(metric.aggregate(reduction="none"))

metric.reset()

The errors are as follows:

{
	"name": "TypeError",
	"message": "BinaryPairwiseMeasures.__init__() got an unexpected keyword argument 'axis'",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /home/bowen/git/prostate/practice.py:13
     11 y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 1.0]]]])
     12 y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])
---> 13 print(metric(y_pred, y))
     15 # second iteration
     16 # shape [batch=1, channel=1, 2, 2]
     17 y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 0.0]]]])

File ~/.conda/envs/pytorch/lib/python3.11/site-packages/monai/metrics/metric.py:347, in CumulativeIterationMetric.__call__(self, y_pred, y, **kwargs)
    327 def __call__(
    328     self, y_pred: TensorOrList, y: TensorOrList | None = None, **kwargs: Any
    329 ) -> torch.Tensor | Sequence[torch.Tensor | Sequence[torch.Tensor]]:
    330     \"\"\"
    331     Execute basic computation for model prediction and ground truth.
    332     It can support  both `list of channel-first Tensor` and `batch-first Tensor`.
   (...)
    345         a `batch-first` tensor (BC[HWD]) or a list of `batch-first` tensors.
    346     \"\"\"
--> 347     ret = super().__call__(y_pred=y_pred, y=y, **kwargs)
    348     if isinstance(ret, (tuple, list)):
    349         self.extend(*ret)

File ~/.conda/envs/pytorch/lib/python3.11/site-packages/monai/metrics/metric.py:80, in IterationMetric.__call__(self, y_pred, y, **kwargs)
     78 if isinstance(y_pred, torch.Tensor):
     79     y_ = y.detach() if isinstance(y, torch.Tensor) else None
---> 80     return self._compute_tensor(y_pred.detach(), y_, **kwargs)
     81 raise ValueError(\"y_pred or y must be a list/tuple of `channel-first` Tensors or a `batch-first` Tensor.\")

File ~/.conda/envs/pytorch/lib/python3.11/site-packages/monai/metrics/wrapper.py:169, in MetricsReloadedBinary._compute_tensor(self, y_pred, y)
    166 y = convert_to_numpy(y)
    168 # Create binary pairwise metric object
--> 169 bpm = BinaryPairwiseMeasures(y_pred, y, axis=tuple(range(2, dims)), smooth_dr=1e-5)
    171 # Is requested metric available?
    172 if self.metric_name not in bpm.metrics:

TypeError: BinaryPairwiseMeasures.__init__() got an unexpected keyword argument 'axis'"
}

ibowennn avatar Oct 10 '24 02:10 ibowennn