How to start with monailabel for new models

To train a new model first organize your data.

  1. Create a folder (e.g., myMonai) and put all your volumes in there.
  2. Within this folder create a labels/original and a labels/final subfolder
  3. Put all your existing labelsmap (you need to export your segmentation as labelmaps) into labels/final folder

Next step is to edit the segmentation script in the apps folder to match your labels as well as modify the UNET resolution. FOr example I have been working with the multilabel app, and I edited the main.py so to reflect my labelIDs, and the resolution/spacing I wanted to use:

class MyApp(MONAILabelApp):
    def __init__(self, app_dir, studies, conf):

        # Zero values are reserved to background. Non zero values are for the labels
        self.label_names = {
            "interparietal": 5,
            "nasal": 6,
            "maxilla_R": 7,
            "molars_R": 8,
            "incisors": 9,
            "premaxilla": 10,
            "palatine_R": 11,
            "jugal_R": 12,
            "squamosal_R": 13,
            "occipital": 14,
            "parietal_R": 15,
            "frontal_R": 16,
            "basisphenoid": 17,
            "presphenoid": 20,
            "background": 0,
        }

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

        # Use Heuristic Planner to determine target spacing and spatial size based on dataset+gpu
        spatial_size = json.loads(conf.get("spatial_size", "[192, 192, 192]"))
        target_spacing = json.loads(conf.get("target_spacing", "[1.09, 1.55, 0.71]"))

After this, fire up the moniaLabel server with these option (obviously you need to modify these to match your app name as well as specific folder structure)

monailabel start_server --app /workspace/apps/skullModel --studies ~myMonai

If you can successfully connect to the server with your Slicer MonaiLabel client, all you have left to train the model is to hit the train button and wait a few hours to see the accuracy increasing. I have trained the models for about couple days (~50000 iterations or so), that worked quite well… There are also other training options you want to explore (such as how you want to split your data into training/test/validation etc). But this should get you started with “a model”.

Once you get an ok model and you are ready to use it in new volumes that do not have segmentations, all you have to is to copy those volumes to the top level of the myMonai folder, and restart the monaiLabel server. Server will detect these new samples, and in the Slicer if you hit the Next Sample button it will automatically process them. If you like the segmentation, you can hit the upload label button to send it to the MonaiLabel server, and after a few more samples like that you can hit the train button again.

So far I only used the multiLabel deepedit app, so I am not sure how much of this carries over to other apps that are distributed with monaiLabel, but hopefully this will help you some…

4 Likes