Skip to content

Label transforms ignore include/exclude filters #1508

Description

@Sal-sal-sal

Description

RemapLabels, RemoveLabels, and OneHot modify label maps that should be excluded by the include or exclude arguments.

Reproduction

import torch
import torchio as tio

subject = tio.Subject(
    a=tio.LabelMap(torch.ones(1, 2, 2, 2)),
    b=tio.LabelMap(torch.ones(1, 2, 2, 2)),
)

result = tio.RemapLabels({1: 9}, include=["a"])(subject)

print(result.a.data.unique())  # tensor([9.])
print(result.b.data.unique())  # tensor([9.]), expected tensor([1.])

The same problem occurs with:

tio.RemapLabels({1: 9}, exclude=["b"])
tio.RemoveLabels([1], include=["a"])
tio.RemoveLabels([1], exclude=["b"])
tio.OneHot(include=["a"])
tio.OneHot(exclude=["b"])

Expected behavior

Only the selected label maps should change.
Excluded label maps should retain their original values and shape.

Possible cause

These transforms iterate over batch.images.items() directly instead of using self._get_images(batch), which applies the include/exclude filters.

Version

Reproduced on main, commit 2b019d2a9659c838408c73ae77327ac5eb87b190, TorchIO 2.0.0a2, using synthetic CPU tensors.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions