Project-MONAI / Project-MONAI/MONAILabel
unable to use inverse_transforms in infers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 891
- Forks
- 269
- Avg merge
- 15h 41m
- Merged PRs (30d)
- 1
Description
Can't add any code to inverse_transforms gives error
class MySegmentation(BasicInferTask):
....
def inverse_transforms(self, data=None) -> Union[None, Sequence[Callable]]:
return [
RestoreOrientationd(keys="pred", ref_image="image")
]
gives error
File "/MONAILabel/monailabel/tasks/infer/basic_infer.py", line 306, in __call__
data = self.run_invert_transforms(data, pre_transforms, self.inverse_transforms(data))
File "/MONAILabel/monailabel/tasks/infer/basic_infer.py", line 397, in run_invert_transforms
transforms = [pre_transforms[n if isinstance(n, str) else n.__name__] for n in names]
File "/MONAILabel/monailabel/tasks/infer/basic_infer.py", line 397, in <listcomp>
transforms = [pre_transforms[n if isinstance(n, str) else n.__name__] for n in names]
AttributeError: 'Orientationd' object has no attribute '__name__'
the only way I can get it to work is to create a fake class and add attribute name as
def inverse_transforms(self, data=None) -> Union[None, Sequence[Callable]]:
class CodeHack:
pass
codehack = CodeHack() # Create an empty employee record
codehack.__name__ = 7
return [codehack]
this would invert the transform number 7 without any errors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in monailabel/tasks/infer/basic_infer.py at BasicInferTask.call and run_invert_transforms, around lines 306 and 397. Trace how inverse_transforms handles RestoreOrientationd and how transform names are resolved. Done means the reported AttributeError no longer occurs when using RestoreOrientationd in inverse_transforms and the transform is inverted as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100