Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final transform module #691

Open
wants to merge 47 commits into
base: clinicadl_v2
Choose a base branch
from

Conversation

thibaultdvx
Copy link
Collaborator

@thibaultdvx thibaultdvx commented Dec 23, 2024

First of all, lots of outdated files deleted: networks/old_network and the associated tests in tests/unittests/nn.

On transforms

Config classes for TorchIO transforms

Supported transforms are:

Supported augmentations are:

Transforms object

The main object of the module, Transforms, now supports config classes as inputs (and still supports raw transforms as well). E.g:

>>> from clinicadl.transforms import Transforms, get_transform_config, Patch
>>> import torchio as tio
>>> transforms = Transforms(
        extraction=Patch(),
        image_transforms=[get_transform_config("ZNormalization")],
        sample_transforms=[tio.Resize((16, 16, 16))],
        image_augmentations=[get_transform_config("RandomBlur")],
        sample_augmentations=[tio.RandomAffine()],
    )
>>> transforms.get_transforms()

(Compose([ZNormalization(masking_method=None)]),
 Compose([Resize(target_shape=[16 16 16], image_interpolation=linear, label_interpolation=nearest)]),
 Compose([RandomBlur()]),
 Compose([RandomAffine()]))

The whole transforms module is tested with 100% coverage.

@thibaultdvx thibaultdvx added the refactoring ClinicaDL refactoring 2024 label Dec 23, 2024
@thibaultdvx thibaultdvx marked this pull request as ready for review December 23, 2024 09:55
@thibaultdvx thibaultdvx mentioned this pull request Dec 23, 2024
Copy link
Collaborator

@camillebrianceau camillebrianceau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one thing: What do you think about doing something like this for the Subject class? This way, we are forced to have an image and a label in the class, while still being able to work with all the TorchIO transforms.

class ClinicaDLSubject(tio.Subject):
    """
    A TorchIO Subject with an 'image' attribute, a TorchIO ScalarImage and a 'label' attribute, which can be either a float, int or torch.Tensor.
    """
    image: tio.ScalarImage
    label: Union[float, int, torch.Tensor]

Otherwise, LGTM ! Thanks :)

self.mask = Path(mask)
else:
self.common_mask = False
self.mask = mask
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.mask = mask
self.mask = Path(mask)

Copy link
Collaborator Author

@thibaultdvx thibaultdvx Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, mask is not a path, but rather a suffix. E.g. with Mask("brain"), the mask will be expected in sub-..._ses-..._brain.nii.gz.
So, I'm not sure we should put it in a Path object.

@thibaultdvx
Copy link
Collaborator Author

Thanks for the review @camillebrianceau. Sounds a good idea, let me check if it works!

@thibaultdvx
Copy link
Collaborator Author

As you suggested @camillebrianceau, I added a subclass of TorchIO Subject with mandatory image and label arguments. I had to overwrite the __copy__ method to make it works with TorchIO's transforms. I'm not a fan of the name ClinicaDLSubject because it is confusing with Subject that we are building in the clinicaio project. So, I suggested the name DataPoint (I was not really inspired haha), but please fell free to suggest if you have a better name.

@thibaultdvx
Copy link
Collaborator Author

I didn't want to put image in the name, as it would be confusing with ImageSample.

@thibaultdvx
Copy link
Collaborator Author

thibaultdvx commented Dec 27, 2024

Besides, I added two TorchIO transforms I had forgotten: Resample and ToCanonical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring ClinicaDL refactoring 2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants