# How to start with monailabel for new models

**URL:** <https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063>\
**Category:** Support\
**Tags:** monailabel\
**Created:** [December 14, 2021, 10:55pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063 "2021-12-14T22:55:54Z")\
**Posts on this page:** 20\
**Page:** 5

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [June 8, 2022, 6:59pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/82 "2022-06-08T18:59:07Z")

</div>

> [@diazandr3s](#):
>
> Hope this helps. Please let me know.

@diazandr3s Not yet 🙂 Have been trying this now on/off for more than two weeks and I would like to get this running before the [workshop](https://github.com/NA-MIC/ProjectWeek/blob/master/PW37_2022_Virtual/MONAILabel_Workshop.md) locally in order to be able to assist other people.

What I have done so far:  
Set up Monailabel on two different systems (laptop 6 GB GPU memory, desktop 16 GB GPU memory) and now switched to the desktop completely due to inconsistent results and -9 server error messages on the laptop.  
Set ML up in WSL Ubuntu, enabled CUDA, did a parallel setup in Windows 11 native, trained, infered, technically it seems to work in both worlds without error messages.

The goal is to train ML with the Lung CT Segmenter to detect “right lung” in total, “left lung” in total, and kind of an airway. It never worked so far. Tried this with lung CT segmenter input as well as with manual segmentations using the ML predefined segments.

All I get is an [ugly block segmentation](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/61) when I use the ML auto segmentation upon “Next sample”…  
This is my start\_server line:

```auto
monailabel start_server --app ./apps/radiology --studies ./datasets/Task06_Lung/imagesTr --conf models segmentation

```

Could you provide a complete and working application that I could start training with the Task06\_Lung dataset before the [MONAILabel workshop](https://github.com/NA-MIC/ProjectWeek/blob/master/PW37_2022_Virtual/MONAILabel_Workshop.md)?

Kind regards  
Rudolf

---

<div class="post-metadata">

**Author:** ![diazandr3s](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/diazandr3s/32/9973_2.png) [@diazandr3s](https://discourse.slicer.org/u/diazandr3s)\
**Post date:** [June 8, 2022, 7:30pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/84 "2022-06-08T19:30:11Z")

</div>

Thanks for your time on this, @rbumm and sorry for the inconvenience.

The first thing I’d like you to check is the labels in the Task06\_Lung dataset. What I see as labels in that dataset are actually lung tumors, not lungs and airway segmentation. See the following image:

 ![sample-lung-dataset.PNG](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/c/ec185aa7f885e1f46fe6c8bf808d470a7878d45b.jpeg)

I might be using a different version of that dataset.

I’m happy to meet on Teams/Zoom early Monday if you’re available.

Please let me know.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [June 8, 2022, 7:46pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/85 "2022-06-08T19:46:06Z")

</div>

> [@diazandr3s](#):
>
> I’m happy to meet on Teams/Zoom early Monday if you’re available

Great, absolutely. Monday is fine.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [June 8, 2022, 7:48pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/86 "2022-06-08T19:48:43Z")

</div>

> [@diazandr3s](#):
>
> What I see as labels in that dataset are actually lung tumors

Noticed that too and thought that I had not used those labels, but will check again

---

<div class="post-metadata">

**Author:** ![diazandr3s](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/diazandr3s/32/9973_2.png) [@diazandr3s](https://discourse.slicer.org/u/diazandr3s)\
**Post date:** [June 8, 2022, 10:28pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/87 "2022-06-08T22:28:59Z")

</div>

Superb! Just sent you the Teams link for next Monday at 13:30 UK time. Please confirm.

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [June 15, 2022, 9:15am UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/88 "2022-06-15T09:15:52Z")

</div>

After great meetings with @diazandr3s we were able to set the MONAILabel lung segmentation up from scratch, train a model, and autosegment lungs and airways.

Windows: We recommend doing this in Windows 11 using Powershell.  
[Follow the instructions from the ML Github](https://docs.monai.io/projects/label/en/latest/installation.html#windows) to install the prerequisites and ML itself.

All in the above link:

- Test that CUDA is available.
- Fork MONAILabel from Github
- Download ML radiology app
- Download lung dataset

Use Slicer 5.1 and ML extension  
We found that the Deepedit model is best suited for our task.  
We modified the deepedit.py in /apps/lib/conf as follows:

```auto
        # Single label
        self.labels = {
            "right lung-1": 1,
            "left lung-2": 2,
            "airways-3": 3,
            "background": 0,
        }

        # Number of input channels - 4 for BRATS and 1 for spleen
        self.number_intensity_ch = 1

        network = self.conf.get("network", "dynunet")

        # Model Files
        self.path = [
            os.path.join(self.model_dir, f"pretrained_{self.name}_{network}.pt"), # pretrained
            os.path.join(self.model_dir, f"{self.name}_{network}.pt"), # published
        ]

        # Download PreTrained Model
        if strtobool(self.conf.get("use_pretrained_model", "false")):
            url = f"{self.conf.get('pretrained_path', self.PRE_TRAINED_PATH)}/deepedit_{network}_singlelabel.pt"
            download_file(url, self.path[0])

        self.target_spacing = (1.0, 1.0, 1.0) # target space for image
        self.spatial_size = (128, 128, 64) # train input size

```

Then we started the ML server with:

```auto
monailabel start_server --app apps/radiology --studies datasets/Task06_Lung/imagesTr --conf models deepedit

```

In 3D Slicer, we connected to ML Server in the ML extension and pressed “Next sample”.  
Then we made a couple of lung and airway segmentation _[with Lung CT Segmenter](https://github.com/rbumm/SlicerLungCTAnalyzer)_ and “submit Label” for each in ML.

We trained a test model with only 50 epochs, and did an autosegmentation on the “next sample”.  
The result was still suboptimal, so I produced 9 more labels in Lung CT Segmenter, uploaded them via “submit Label” to ML one by one, then trained the model with CUDA on my GTX 3070 Ti for 1000 epochs (10 hours)  
After that, autosegmentation was very fast and shows promising results:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/1/111532765a521ee4b2c8222245997dd0fbb3520e.jpeg)

---

<div class="post-metadata">

**Author:** ![diazandr3s](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/diazandr3s/32/9973_2.png) [@diazandr3s](https://discourse.slicer.org/u/diazandr3s)\
**Post date:** [June 15, 2022, 9:22am UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/89 "2022-06-15T09:22:59Z")

</div>

Many thanks for the detailed message, @rbumm 🙂

---

<div class="post-metadata">

**Author:** ![deboshree\_roy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deboshree_roy/32/17026_2.png) [@deboshree\_roy](https://discourse.slicer.org/u/deboshree_roy)\
**Post date:** [October 25, 2022, 12:29pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/90 "2022-10-25T12:29:20Z")

</div>

Currently, my goal is to use my pre-trained model in 3DSlicer for interactive segmentation. The discussions in the group seem to be in the same line and illuminating. I am looking for suggestions in my work. The procedure that I followed is -  
I have generated a pre-trained model and added the path of the .pth file to the lib → conf → deepedit.py file. I edited the labels accordingly.

On starting the monailabel server and loading the model, I run the autosegment. I can see the same .pth file being loaded in the cmd window.

The model developed (.pth) has been tested to generate accurate results. On running in 3D Slicer it generates completely odd results.

My doubt is that my procedure to load the .pth file into the module is correct ? Do I need to do anything more ? Perhaps in the infer folder ?

Thanks

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 10, 2023, 9:56pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/92 "2023-02-10T21:56:42Z")

</div>

Hello, I have a similar problem with this ‘‘CUDA error’’ when I am using the App radiology app and the spleen dataset which was used in an example in a tutorial.

 ![Screenshot_10](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/9/f9d7ebcc541cfdede040c1cec58d986b4c74d4e5.jpeg)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [February 11, 2023, 12:22pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/93 "2023-02-11T12:22:58Z")

</div>

This indicates that the GPU of your computer has insufficient dedicated video RAM - at least 6 GB is recommended to run the server. Please check your NVIDIA control panel → System Information.  
You may consider upgrading your GPU to a more recent model or running the server in the cloud.

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 11, 2023, 12:40pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/94 "2023-02-11T12:40:31Z")

</div>

Hello and thank you very much for your answer !!

Actually,I checked all that when I was installing MONAI.

My GPU is GeForce MX450 and as I was searching it is compatible with CUDA 10.0 to 10.2.

What GPU in your opinion I should install so that MONAI can work ?

Στις Σάβ, 11 Φεβ 2023, 13:23 ο χρήστης Rudolf Bumm via 3D Slicer Community \<[notifications@slicer.discoursemail.com](mailto:notifications@slicer.discoursemail.com)\> έγραψε:

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [February 11, 2023, 1:21pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/95 "2023-02-11T13:21:17Z")

</div>

We would [recommend a RTX 3060](https://discourse.slicer.org/t/new-extension-fully-automatic-whole-body-ct-segmentation-in-2-minutes-using-totalsegmentator/26710/51) (12 GB RAM) or RTX 3090 (24 GB) for current CUDA based deep learning purposes. Got a MONAILabel server running on a GTX 1060 (6 GB) but this is the very low limit.

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 11, 2023, 3:34pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/96 "2023-02-11T15:34:41Z")

</div>

Thank you a lot for your answers, you saved me valuable time for this issue.

Judging from the prices of these graphic cards,

Do you believe running MONAI in the cloud as you said would be a valid solution to this situation ?

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 11, 2023, 3:40pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/97 "2023-02-11T15:40:10Z")

</div>

If yes, which cloud do you suggest for AI procedures such as this?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 11, 2023, 4:57pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/98 "2023-02-11T16:57:45Z")

</div>

The [instructions here for AWS](https://projectweek.na-mic.org/PW38_2023_GranCanaria/Projects/SlicerCloud/) are convenient for windows users. And linux instructions are [here for Google](https://learn.canceridc.dev/cookbook/virtual-machines/idc-desktop) but similar techniques can be used on other cloud providers. The nice thing about these environments is that there are many GPU options and you only pay for the time you need.

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 11, 2023, 5:16pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/99 "2023-02-11T17:16:00Z")

</div>

Thank you very much:) Kind of basic question, Docker for Windows cannot work in this case?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 11, 2023, 5:22pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/100 "2023-02-11T17:22:53Z")

</div>

You can use docker on any of these platforms if you find it useful. Personally I find that for the cloud it’s more convenient just to use the native OS so there’s only one layer of GPU drivers to worry about.

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 13, 2023, 2:52pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/101 "2023-02-13T14:52:07Z")

</div>

Hello again

I just created an account on AWS for window users. However, I cannot download the template you provided in a link to use it in the stack…

Also, I have a question regarding the cost of the AWS. If the MONAILabel is under the free use of AWS or not.

Thank you a lot for your valuable time and help  
Best  
Spiros

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 13, 2023, 3:14pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/102 "2023-02-13T15:14:21Z")

</div>

My bad…I downloaded it.

---

<div class="post-metadata">

**Author:** ![Spiros\_Karkavitsas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/spiros_karkavitsas/32/18224_2.png) [@Spiros\_Karkavitsas](https://discourse.slicer.org/u/Spiros_Karkavitsas)\
**Post date:** [February 13, 2023, 3:29pm UTC](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063/103 "2023-02-13T15:29:21Z")

</div>

Hello again

I followed the instructions for AWS and tried to create a cloud for MONAI using the already template.

However, I got this ROLLBACK\_COMPLETE message:

 ![Screenshot_20](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/2/c2242451185da5e574fa38f852e528cba24be19b.jpeg)

What am I doing wrong here ?

Best and thank you all for your time,  
Spiros.

[Previous page](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063.md?page=4)

[Next page](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063.md?page=6)
