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

Adding transformation adaptor #193

Merged
merged 4 commits into from Mar 3, 2022
Merged

Conversation

vale-salvatelli
Copy link
Contributor

PR to add a transformation adaptor to allow transformations working only on Tensors/Images to work with a dict in input

@vale-salvatelli vale-salvatelli changed the title WIP: adding transformation adaptor Adding transformation adaptor Mar 3, 2022
maxilse
maxilse previously approved these changes Mar 3, 2022
if k_output is None:
ditems = ret
else:
if isinstance(ret, type(ditems[k_output])):
Copy link
Member

Choose a reason for hiding this comment

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

For my information, I'm not sure I understand this. Is the dictionary expected to already contain k_output? And why do the types need to match? This seems overly restrictive—consider e.g. loading an image tensor from a path.

Another comment is that the MONAI docs suggest that transforms shouldn't modify input dictionaries in-place, but rather call ditems.copy() before assigning the outputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they're both good comments:

  • correct we could extend this adaptor to be compatible with a broader set of transformations and also give the option to add a key rather than just overwriting. I wanted to keep this as simple as possible to solve our current case.
  • do you know why MONAI suggest to copy? here I am a bit worried about memory consumption if every transformation is creating a copy but happy to follow up on this

Copy link
Member

Choose a reason for hiding this comment

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

On the second point, it's just a shallow copy of the dictionary, in case the original needs to be used elsewhere (e.g. if passed to multiple parallel transformations).

@vale-salvatelli vale-salvatelli merged commit 0250715 into main Mar 3, 2022
@vale-salvatelli vale-salvatelli deleted the vsalva/add_transform_adaptor branch March 3, 2022 13:36
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

4 participants