Skip to content

boolean indexing of batched metatensor #6777

Closed

Description

@wyli

Describe the bug

import torch
from monai.data import MetaTensor

data = MetaTensor(torch.zeros([2, 96, 96]))
data.is_batch = True

mask = torch.tensor([True, False])
print(data[mask].shape)
Traceback (most recent call last):
  File "/Users/Documents/MONAI/my_test_1.py", line 9, in <module>
    print(data[mask].shape)
  File "/Users/Documents/MONAI/monai/data/meta_tensor.py", line 297, in __torch_function__
    ret = MetaTensor.update_meta(ret, func, args, kwargs)
  File "/Users/Documents/MONAI/monai/data/meta_tensor.py", line 237, in update_meta
    ret_meta = decollate_batch(args[0], detach=False)[batch_idx]
TypeError: only integer tensors of a single element can be converted to an index

Activity

  1. added
    bugSomething isn't working
    on Jul 26, 2023
  2. added a commit that references this issue on Jul 27, 2023
    9e2d381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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