Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/torchio/transforms/augmentation/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ def inverse(self, warn: bool = True) -> Compose:
)
return result

def to_hydra_config(self) -> dict:
"""Return a dictionary representation of the transform for Hydra instantiation."""
target = self._get_name_with_module()
transform_dict = {'_target_': target}
transform_dict['transforms'] = []
transform_dict.update(self._get_reproducing_arguments())
for transform in self.transforms:
transform_dict['transforms'].append(transform.to_hydra_config())
return transform_dict


class OneOf(RandomTransform):
"""Apply only one of the given transforms.
Expand Down
11 changes: 11 additions & 0 deletions src/torchio/transforms/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,14 @@ def get_mask_from_bounds(
mask = torch.zeros_like(tensor, dtype=torch.bool)
mask[:, i0:i1, j0:j1, k0:k1] = True
return mask

def _get_name_with_module(self) -> str:
"""Return the name of the transform including its module."""
return f'{self.__class__.__module__}.{self.__class__.__name__}'

def to_hydra_config(self) -> dict:
"""Return a dictionary representation of the transform for Hydra instantiation."""
target = self._get_name_with_module()
transform_dict = {'_target_': target}
transform_dict.update(self._get_reproducing_arguments())
return transform_dict
Loading