Skip to content

__call__() and _compute_metric() in SSIMMetric  #5498

@Joeycho

Description

@Joeycho

Describe the bug
Hello, I cannot store values as buffers in SSIMMetric, for calculating the metric later.

self.ssim_metric._compute_metric(x,y) # By _compute_metric() it works.
self.ssim_metric(x,y) # It does not work.

To Reproduce

x = torch.ones([2,1,10,10,10])/2 # ground truth
y = torch.ones([2,1,10,10,10])/2 # prediction
self.ssim_metric = SSIMMetric(data_range =torch.tensor([255.0], device="cpu") ,spatial_dims= 3)
           
# the following line should print 1.0 (or 0.9999)
print(self.ssim_metric(x,y))

Expected behavior

tensor(1.)

Screenshots

*** TypeError: split expects at least a 1-dimensional tensor. `data` should be a batch-first tensor or a list of channel-first tensors, got <class 'torch.Tensor'>

Environment

Ensuring you use the relevant python executable, please paste the output of:

================================
Printing MONAI config...
================================
MONAI version: 1.0.0
Numpy version: 1.23.1
Pytorch version: 1.12.1
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 170093375ce29267e45681fcec09dfa856e1d7e7
MONAI __file__: /u/home/xxx/.conda/envs/unet_torch/lib/python3.10/site-packages/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.
Nibabel version: 4.0.2
scikit-image version: 0.19.3
Pillow version: 9.2.0
Tensorboard version: 2.10.1
gdown version: NOT INSTALLED or UNKNOWN VERSION.
TorchVision version: 0.13.1
tqdm version: 4.64.1
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: 5.9.2
pandas version: 1.5.0
einops version: NOT INSTALLED or UNKNOWN VERSION.
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies


================================
Printing system config...
================================
System: Linux
Linux version: Ubuntu 20.04.5 LTS
Platform: Linux-5.14.0-1052-oem-x86_64-with-glibc2.31
Processor: x86_64
Machine: x86_64
Python version: 3.10.4
Process name: python
Command: ['python', '-c', 'import monai; monai.config.print_debug_info()']

================================
Printing GPU config...
================================
Num GPUs: 2
Has CUDA: True
CUDA version: 11.3
cuDNN enabled: True
cuDNN version: 8302
Current device: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions