Skip to content

bug: MetaTensor .shape() returns Tuple instead of torch.Size #5532

@myron

Description

@myron

MetaTensor .shape() returns tuple instead of torch.Size. If MetaTensor is subclass of torch.Tensor, it should not change it methods

import torch
from monai.data import MetaTensor

a = torch.rand(1,2,3)
print(a.shape, type(a.shape)) # prints torch.Size([1, 2, 3]) <class 'torch.Size'>

a_meta = MetaTensor(a)
print(a_meta.shape, type(a_meta.shape)) # prints (1, 2, 3) <class 'tuple'>

print('numel of last two dims', a.shape[1:].numel()) # prints 6
print('numel of last two dims', a_meta.shape[1:].numel()) # crashes

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'numel'

Metadata

Metadata

Assignees

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