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

masking_method in Mask class is not saved as argument (preventing applying the inverse transform) #1136

Closed
1 task done
lchauvin opened this issue Jan 18, 2024 · 0 comments · Fixed by #1137
Closed
1 task done

Comments

@lchauvin
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Problem summary

When trying to get an inverse transform after composing a transform with a Mask(masking_method='mymask'), the masking_method is not saved as argument (like it's the case with ZNormalization for example).
Then, when trying to get the inverse transform, I get:

File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 212, in apply_inverse_transform
  inverse_transform = self.get_inverse_transform(**kwargs)
File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 198, in get_inverse_transform
  history_transform = self.get_composed_history(
File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 176, in get_composed_history
  transforms = self.get_applied_transforms(
File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 160, in get_applied_transforms
  transform = name_to_transform[transform_name](**arguments)
TypeError: __init__() missing 1 required positional argument: 'masking_method'

Code for reproduction

import torchio as tio

if __name__ == '__main__':
    data = tio.Subject(mask=tio.LabelMap('path_to_mask'),image=tio.ScalarImage('path_to_image'))
transform = tio.Compose([
    tio.ToCanonical(),
    tio.CropOrPad(target_shape=(100,100,100), mask_name='mask'),
    tio.ZNormalization(masking_method='mask'),
    tio.Mask(masking_method='mask'),
    ])

transform_data = transform(data)

transform_data.apply_inverse_transform()

Actual outcome

TypeError: init() missing 1 required positional argument: 'masking_method'

Error messages

Traceback (most recent call last):
  File "/scratch/02/lchauvin/workspace/projects/VntrcNet/predict.py", line 115, in <module>
    main(hp, name=args.name)
  File "/scratch/02/lchauvin/workspace/projects/VntrcNet/predict.py", line 70, in main
    subject_data_inverse = subject_data.apply_inverse_transform()
  File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 207, in apply_inverse_transform
    inverse_transform = self.get_inverse_transform(**kwargs)
  File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 193, in get_inverse_transform
    history_transform = self.get_composed_history(
  File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 171, in get_composed_history
    transforms = self.get_applied_transforms(
  File "/scratch/02/lchauvin/workspace/miniconda3/envs/VntrcNet/lib/python3.9/site-packages/torchio/data/subject.py", line 154, in get_applied_transforms
    transform = name_to_transform[transform_name](**arguments)
TypeError: __init__() missing 1 required positional argument: 'masking_method'

Expected outcome

The inverted transform

System info

No response

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 a pull request may close this issue.

1 participant