Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Read monai/metrics/wrapper.py at MetricsReloadedBinary._compute_tensor and compare its BinaryPairwiseMeasures call with the installed MetricsReloaded API. Re-run the supplied MONAI example; done means both metric calls and aggregate(reduction="none") execute without the unexpected axis error.

Written by the indexing model from the issue text.

Description

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'"
}
Dominant language
Python
Stars
105
Forks
18
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Project-MONAI/MetricsReloaded

All issues in Project-MONAI/MetricsReloaded

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.