Project-MONAI / MONAILabel

MONAI Label is an intelligent open source image labeling and learning tool.
https://docs.monai.io/projects/label
Apache License 2.0
610 stars 196 forks source link

How to do cascading infer with MonaiLabel #1358

Closed XU-Wenyi closed 1 year ago

XU-Wenyi commented 1 year ago

We have a situation, firstly we segment a certain organ in the image, and then we segment a certain type of focus. How we run a cascade network inference by using MonaiLabel.

diazandr3s commented 1 year ago

Hi @XU-Wenyi,

This is a very good question. Cascade models are robust and can help to solve complex problems. Here you can find an example of a multiple-stage (or cascade) model in MONAI Label: https://github.com/Project-MONAI/MONAILabel/tree/main/sample-apps/radiology#multistage-vertebra-segmentation

Essentially, you first create the infer classes (localization_spine, localization_vertebra, and segmentation_vertebra) independently and then execute them in order in what we call a pipeline here: https://github.com/Project-MONAI/MONAILabel/blob/main/sample-apps/radiology/lib/infers/vertebra_pipeline.py#L138-L153

The same applies to train classes: https://github.com/Project-MONAI/MONAILabel/tree/main/sample-apps/radiology/lib/trainers

Hope this helps,

Liucd0520 commented 1 year ago

@diazandr3s Thanks for your reply, I use the multiple stage vertebra segmentation model and success. Meanwhile, I realize that this tutorial is a 'tree-stage' task, and is not applicable at 'two-stage' task (1. Organ location; 2. Tumor ). I try to modify the configs and infers,But the vertebra_pipeline.py is difficult to read and adjust.

Is there some more targeted recommendations and tutorials for me, Thanks

diazandr3s commented 1 year ago

You're right, the vertebra segmentation pipeline is a 3-stage system. You have one infer and one train class per stage.

Each stage should be trained independently. For inference, you can run each stage independently or use all of them with the infer pipeline.

You could modify the pipeline to only work on two stages. Here is another example of this: https://projectweek.na-mic.org/PW38_2023_GranCanaria/Projects/TeethSegmentation/

You can find the code for the dental 2-stage model here: https://github.com/dgmato/MONAILabel/tree/dental-pipeline/sample-apps/radiology

Here is the infer pipeline: https://github.com/dgmato/MONAILabel/blob/dental-pipeline/sample-apps/radiology/lib/infers/dental_pipeline.py#L92-L104

Maybe @dgmato may also want to comment on his experience working with multistage models on MONAI Label.

SachidanandAlle commented 1 year ago

you can implement directly InferTask and add any customized processing in call method

Derive your InferTask from this: https://github.com/Project-MONAI/MONAILabel/blob/main/monailabel/interfaces/tasks/infer_v2.py