Project-MONAI / monai-deploy-app-sdk

MONAI Deploy App SDK offers a framework and associated tools to design, develop and verify AI-driven applications in the healthcare imaging domain.
Apache License 2.0
94 stars 48 forks source link

[BUG] MONAI 0.9.1 is not (backwards) compatible with MONAI Seg Inference Operator #320

Closed MMelQin closed 2 years ago

MMelQin commented 2 years ago

Describe the bug

Steps/Code to reproduce bug

Given that monai v0.9.1 has been released and published, the App SDK needs to declare incompatibility with this version until the App SDK implementation is updated and tested working with monai 0.9.1.

Environment details (please complete the following information)

Additional context See attached log files from running the apps (to be attached), with a brief snippet shown below:

Traceback (most recent call last):
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/transforms/transform.py", line 90, in apply_transform
    return _apply_transform(transform, data, unpack_items)
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/transforms/transform.py", line 54, in _apply_transform
    return transform(parameters)
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/transforms/post/dictionary.py", line 642, in __call__
    transform_info = d[InvertibleTransform.trace_key(orig_key)]
KeyError: 'image_transforms'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/mqin/src/monai-app-sdk/.venv/bin/monai-deploy", line 33, in <module>
    sys.exit(load_entry_point('monai-deploy-app-sdk', 'console_scripts', 'monai-deploy')())
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/deploy/cli/main.py", line 116, in main
    execute_exec_command(args)
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/deploy/cli/exec_command.py", line 76, in execute_exec_command
    runpy.run_path(app_path, run_name="__main__")
  File "/usr/lib/python3.8/runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/mqin/src/monai-app-sdk/examples/apps/ai_livertumor_seg_app/app.py", line 90, in <module>
    app_instance.run()
  File "/home/mqin/src/monai-app-sdk/examples/apps/ai_livertumor_seg_app/app.py", line 37, in run
    super().run(*args, **kwargs)
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/deploy/core/application.py", line 429, in run
    executor_obj.run()
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/deploy/core/executors/single_process_executor.py", line 125, in run
    op.compute(op_exec_context.input_context, op_exec_context.output_context, op_exec_context)
  File "/home/mqin/src/monai-app-sdk/examples/apps/ai_livertumor_seg_app/livertumor_seg_operator.py", line 105, in compute
    infer_operator.compute(op_input, op_output, context)
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/deploy/operators/monai_seg_inference_operator.py", line 226, in compute
    d = [post_transforms(i) for i in decollate_batch(d)]
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/deploy/operators/monai_seg_inference_operator.py", line 226, in <listcomp>
    d = [post_transforms(i) for i in decollate_batch(d)]
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/transforms/compose.py", line 173, in __call__
    input_ = apply_transform(_transform, input_, self.map_items, self.unpack_items, self.log_stats)
  File "/home/mqin/src/monai-app-sdk/.venv/lib/python3.8/site-packages/monai/transforms/transform.py", line 114, in apply_transform
    raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.post.dictionary.Invertd object at 0x7f5e3e4ac4f0>
wyli commented 2 years ago

I think the issue is from the v0.9.1 change of ToTensor (the transform removes the meta dict in this version). In fact the images are now metatensors, ToTensor is not needed anymore, so removing all the ToTensor would probably address this issue, e.g. here https://github.com/Project-MONAI/monai-deploy-app-sdk/blob/1a8cf866dc34400c72a487f0a23a7577e3f52012/examples/apps/ai_unetr_seg_app/unetr_seg_operator.py#L117

MMelQin commented 2 years ago

I think the issue is from the v0.9.1 change of ToTensor (the transform removes the meta dict in this version). In fact the images are now metatensors, ToTensor is not needed anymore, so removing all the ToTensor would probably address this issue, e.g. here

https://github.com/Project-MONAI/monai-deploy-app-sdk/blob/1a8cf866dc34400c72a487f0a23a7577e3f52012/examples/apps/ai_unetr_seg_app/unetr_seg_operator.py#L117

Thanks, yes, a separate issue was create to fix/update the code to migrate to MetaTensor. My plan is to get this PR to merge first and then circle back once the compatibility issue is addressed.

pdogra89 commented 2 years ago

@MMelQin @dbericat @deepib - Thanks Ming ! When would this be fixed ?Please share ETA ?

MMelQin commented 2 years ago

@MMelQin @dbericat @deepib - Thanks Ming ! When would this be fixed ?Please share ETA ?

It will be released in App SDK 0.5, which has been delayed till early Oct due to the additional work for IHE Connectathon IAIP.

Nic-Ma commented 2 years ago

Hi @MMelQin ,

I just want to double confirm, will this early Oct release 0.5 be compatible with MONAI 1.0.0?

Thanks in advance.

MMelQin commented 2 years ago

Hi @MMelQin ,

I just want to double confirm, will this early Oct release 0.5 be compatible with MONAI 1.0.0?

Thanks in advance.

Yes, @Nic-Ma , the App SDK v0.5 needs to be compatible with MONAI 1.0.0.