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

Creation of Prepare Data Config #568

Merged

Conversation

camillebrianceau
Copy link
Collaborator

@camillebrianceau camillebrianceau commented Apr 29, 2024

  • Creation of the transforms folder and files
  • Creation of the PrepareDataConfig and so the PrepareDataImageConfig, PrepareDataPatchConfig, PrepareDataSliceConfig and PrepareDataRoiConfig
  • Creation of the prepare_data_param folder with the CLI adapted to the Config classes
  • Creation of new Enum: DTIMeasure, DTISpace, ExtractionMethod, SliceDirection, SliceMode, Template, Pattern
  • Adaptation of the code and the tests to these changes.

Future work: creation of unittests, better adaptation to Config in the data.py file,

use_uncropped_image=preprocessing_dict["use_uncropped_image"],
save_features=preprocessing_dict["prepare_dl"],
patch_size=preprocessing_dict["patch_size"],
stride_size=preprocessing_dict["stride_size"],
Copy link
Member

Choose a reason for hiding this comment

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

Something that could be useful is to define custom constructors for these classes:

class PrepareDataPatchConfig:
    caps_directory: Path
    preprocessing_cls: Preprocessing
    use_uncropped_image: ...

    @classmethod
    def from_preprocessing(cls, caps_directory: Path, preprocessing: dict):
        return cls(
            caps_directory,
            Preprocessing(preprocessing_dict["preprocessing"]),
            preprocessing_dict["use_uncropped_image"],
            ....
        )

This way, the code would be very simple:

self.config = PrepareDataPatchConfig.from_preprocessing(caps_directory, preprocessing_dict)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But these lines are just temporary...

@@ -526,6 +547,15 @@ def __init__(
multi_cohort=multi_cohort,
)

self.config = PrepareDataROIConfig(
Copy link
Member

Choose a reason for hiding this comment

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

You might be able to use inheritance between these classes (if it makes sense) to factorize some code.

Copy link
Collaborator

@thibaultdvx thibaultdvx left a comment

Choose a reason for hiding this comment

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

LGTM, except a mistake i told you about ConfigDict. Plus some minor remarks

clinicadl/prepare_data/prepare_data_cli.py Show resolved Hide resolved
clinicadl/prepare_data/prepare_data_cli.py Show resolved Hide resolved
clinicadl/prepare_data/prepare_data_cli.py Show resolved Hide resolved
save_features: bool = False
extract_method: ExtractionMethod

class ConfigDict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry @camillebrianceau, I told that you that we should use ConfigDict instead of Config (which is deprecated), but it turns out that they are not use in the same way. Some examples:

class ClassTest(BaseModel):
    a: str = "a"
    class Config:
        validate_assignment=True

test = ClassTest()
test.a = 0

will raise a ValidationError as expected, but the Config class usage is deprecated.

class ClassTest(BaseModel):
    a: str = "a"
    class ConfigDict:
        validate_assignment=True

test = ClassTest()
test.a = 0

will not raise any error unfortunately.

from pydantic import BaseModel, ConfigDict
class ClassTest(BaseModel):
    a: str = "a"
    model_config = ConfigDict(validate_assignment=True)

test = ClassTest()
test.a = 0

will raise a ValidationError as expected.

To sum up, we should use the last option.

clinicadl/prepare_data/prepare_data_param/option.py Outdated Show resolved Hide resolved
@camillebrianceau camillebrianceau merged commit a45aab9 into aramis-lab:refactoring May 15, 2024
13 checks passed
@camillebrianceau camillebrianceau deleted the cb_config_prep_data branch May 15, 2024 14:09
camillebrianceau added a commit to camillebrianceau/clinicadl that referenced this pull request May 29, 2024
camillebrianceau added a commit to camillebrianceau/clinicadl that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants