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

New caps dataset #562

Open
wants to merge 12 commits into
base: refactoring
Choose a base branch
from
Open

Conversation

HuguesRoy
Copy link

Creation of a new folder caps_dataset_refactoring containing two .py files:

  • caps_dataset.py: low level class caps-dataset (work only for Image datasets)
  • concat_dataset.py: classes for concatenation, stacking and creation of dataset from control file

For the moment, these files are not connected to the rest of clinicadl.

@HuguesRoy HuguesRoy added the refactoring ClinicaDL refactoring 2024 label Apr 22, 2024
@pep8speaks
Copy link

pep8speaks commented Apr 22, 2024

Hello @HuguesRoy! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-05-15 09:52:28 UTC

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.

Thanks a lot @HuguesRoy! Could you please try to write the docstrings with the template I gave you?

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @HuguesRoy !
I had a quick look and made some suggestions on caps_dataset.py, mainly on type hints.
Let me know if some things are not clear.

def elem_index(self):
pass

def label_fn(self, target: Union[str, float, int]) -> Union[float, int]:
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the method can return None:

Suggested change
def label_fn(self, target: Union[str, float, int]) -> Union[float, int]:
def label_fn(self, target: Union[str, float, int]) -> Optional[Union[float, int]]:

label: value of the label usable in criterion.
"""
domain_code = {"t1": 0, "flair": 1}
return domain_code[str(target)]
Copy link
Member

Choose a reason for hiding this comment

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

Can really target be a float, an integer, or a string ? From the dict above, it seems it can only take two values: "t1" or "flair".

else:
return self.label_code[str(target)]

def domain_fn(self, target: Union[str, float, int]) -> Union[float, int]:
Copy link
Member

Choose a reason for hiding this comment

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

Might be missing things, but it seems it can only return integers, right ?

Suggested change
def domain_fn(self, target: Union[str, float, int]) -> Union[float, int]:
def domain_fn(self, target: Union[str, float, int]) -> int:

Args:
idx: row number of the meta-data contained in self.df
Returns:
dictionary with following items:
Copy link
Member

Choose a reason for hiding this comment

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

If all subclasses return dictionaries with the same structure, it might be valuable to build a custom type for this instead of relying on dictionaries.

@abc.abstractmethod
def __getitem__(self, idx: int) -> Sample:
    ....

@dataclass
class Sample:
    image: torch.Tensor
    label: int | float
    participant_id: str
    ...

WDYT?



##################################
# Transformations
Copy link
Member

Choose a reason for hiding this comment

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

Could be worth putting these in a separate module as this file is already pretty large. WDYT ?



################################
# TSV files loaders
Copy link
Member

Choose a reason for hiding this comment

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

Same kind of comment here

################################
# TSV files loaders
################################
def load_data_test(test_path: Path, diagnoses_list, baseline=True, multi_cohort=False):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def load_data_test(test_path: Path, diagnoses_list, baseline=True, multi_cohort=False):
def load_data_test(test_path: Path, diagnoses_list: list[str], baseline: bool = True, multi_cohort: bool = False) -> pd.DataFrame:

raise ClinicaDLArgumentError(
"If multi_cohort is given, the TSV_DIRECTORY argument should be a path to a TSV file."
)
else:
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to have an else statement here since you raise in the if.
This would spare one level of indentation for the following code block.

return test_df


def load_data_test_single(test_path: Path, diagnoses_list, baseline=True):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def load_data_test_single(test_path: Path, diagnoses_list, baseline=True):
def load_data_test_single(test_path: Path, diagnoses_list: list[str], baseline: bool = True) -> pd.DataFrame:

@thibaultdvx thibaultdvx marked this pull request as draft April 25, 2024 12:16
broken path solved
@camillebrianceau camillebrianceau marked this pull request as ready for review May 15, 2024 11:38
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.

None yet

4 participants