Project-MONAI / Project-MONAI/MONAILabel

unable to use inverse_transforms in infers

Open
#1,265 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0.7.0
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.