# 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:** 1\
**Showing post:** 88

<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)

---

_[View the full topic](https://discourse.slicer.org/t/how-to-start-with-monailabel-for-new-models/21063)._
