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

Transforms in CapsDataset #687

Merged

Conversation

thibaultdvx
Copy link
Collaborator

@thibaultdvx thibaultdvx commented Dec 17, 2024

PR on CapsDataset, Preprocessing and Transforms.

For CapsDataset:

  • Add label and masks arguments in CapsDataset: label can be either None (reconstruction), a mask (segmentation) or a column of the tsv data (classification, regression). masks are masks that are potentially necessary to compute some transforms. Consequently, I added methods _get_masks and _get_label that are called in the __getitem__.
  • Change CapsDataset's __getitem__ to handle TorchIO's Subject (following Continuing refactoring of the extraction objects #686).
  • As the CapsDataset class was growing pretty big, I took check_preprocessing and prepare_data methods out of it. check_preprocessing is now in CapsReader; and prepare_data is now a function that takes a CapsDataset as an input.
  • Remove CapsDatasetSample as CapsDataset's __getitem__ now returns a Sample object (following Continuing refactoring of the extraction objects #686).

For Preprocessing:

  • Rename BasePreprocessing to Preprocessing and the enum Preprocessing to PreprocessingMethod. The motivation is to have Preprocessing in type hints.
  • Remove mentions of preprocessings t2-linear and t1-extensive as they no longer exist.
  • Remove arguments use_uncropped_image for PreprocessingDTI and PreprocessingCustom as it is only an argument for linear pipelines.

For Transforms:

  • Remove size_reduction, size_reduction_factor and normalize in Transforms, as equivalent transforms can easily be passed.
  • Add unittests to test the Transforms object.

Sorry for the huge PR. Besides, these are only suggestions, feel free to question them!

@thibaultdvx thibaultdvx changed the title Ttransforms in CapsDataset Transforms in CapsDataset Dec 17, 2024
@thibaultdvx thibaultdvx added the refactoring ClinicaDL refactoring 2024 label Dec 17, 2024
@thibaultdvx thibaultdvx marked this pull request as ready for review December 18, 2024 17:21
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.

LGTM ! Thanks :)

transforms: Transforms,
data: Optional[Union[pd.DataFrame, Path]] = None,
caps_directory: Union[str, Path],
preprocessing: Preprocessing,
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we can give a default preprocessing like PreprocessingT1() WDYT ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think T1 is the most common (at least in our lab).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

will look for masks with that values as a suffix. For example, if the image of the subject
'sub-001' for the session 'ses-M000' is in 'sub-001/ses-M000/sub-001_ses-M000_T1w.nii.gz'
and `masks=["brain", "hippocampus"]`, it will look for the masks in
'sub-001/ses-M000/sub-001_ses-M000_brain.nii.gz' and 'sub-001/ses-M000/sub-001_ses-M000_hippocampus.nii.gz'.
"""

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
caps_directory = Path(caps_directory) # maybe to put in the CapsReader

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is done in the CapsReader yes:

self.input_directory = Path(input_dir)

clinicadl/data/datasets/caps_dataset.py Outdated Show resolved Hide resolved
@thibaultdvx thibaultdvx merged commit 1a7b08b into aramis-lab:clinicadl_v2 Dec 19, 2024
10 checks passed
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