# Unexpected results from training new model in Monai Label

**URL:** <https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681>\
**Category:** Support\
**Tags:** monai, monailabel\
**Created:** [August 8, 2022, 4:27pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681 "2022-08-08T16:27:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahranahm](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mahranahm](https://discourse.slicer.org/u/mahranahm)\
**Post date:** [August 8, 2022, 4:27pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/1 "2022-08-08T16:27:33Z")

</div>

Hi 3D slicer community,

We are working to train a new model to segment the heart. We have 6 pre-labelled scans which I am using for the initial training. I kept all the parameters on default except increasing the max\_epoch to 1000. I am using a cloud GPU for the server (A100 (40 GB), 30 VCPUs, 200 GiB RAM, 512 GiB SSD) and SSH with port forwarding to my local 3Dslicer 5.0.3 r30893. I added the correct labels to the segmentation.py and turned the pre.trained model to “false”. My first model didn’t include a background label but however in my second run I included it but with no better results.

Here is what autosegmentation of a validation set looks like:

 ![Screen Shot 2022-08-05 at 5.14.16 PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/0/a03c191c7cf6d21de312db5be99c133b27576ddc.jpeg)

Here is a the labelled segmentations found in the (labels/final) folder.

 ![Screen Shot 2022-08-08 at 12.00.31 PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/a/9a6207188ebfb880329294f0aa622cbde2c25c21.jpeg)

Does anyone know how to improve this?

---

<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:** [August 8, 2022, 5:31pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/2 "2022-08-08T17:31:22Z")

</div>

> [@mahranahm](#):
>
> Here is a the labelled segmentations found in the (labels/final) folder.

Is that one of the labels you have used for training?

---

<div class="post-metadata">

**Author:** ![mahranahm](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mahranahm](https://discourse.slicer.org/u/mahranahm)\
**Post date:** [August 8, 2022, 5:34pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/3 "2022-08-08T17:34:58Z")

</div>

@rbumm yes thats correct, with a total of 6 labelled volumes

---

<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:** [August 8, 2022, 5:48pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/4 "2022-08-08T17:48:12Z")

</div>

Did you include sternum, ribs, lungs, and airways on purpose? Maybe leave out those for the next test if acceptable

> [@mahranahm](#):
>
> My first model didn’t include a background label

The “segmentation” model does not need a background label.

---

<div class="post-metadata">

**Author:** ![mahranahm](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mahranahm](https://discourse.slicer.org/u/mahranahm)\
**Post date:** [August 8, 2022, 7:51pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/5 "2022-08-08T19:51:44Z")

</div>

Ideally I would like to have these things segmented as well, but left them out for a test to see the results but not much changed. See results below:

 ![Screen Shot 2022-08-08 at 3.37.57 PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/2/123c8af3e0ff8e627985f08e075e2bd4fe854cc8.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:** [August 8, 2022, 8:07pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/6 "2022-08-08T20:07:15Z")

</div>

Ok are you able to do the auto-segmentation on the trained volumes with better results?

Are all label numbers identical for your targets?

> [@mahranahm](#):
>
> , but left them out for a test to see the results but not much changed. See results below:

This last test volume seems to be a NIFTI format - did you train on NIFT images as well ?

---

<div class="post-metadata">

**Author:** ![mahranahm](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mahranahm](https://discourse.slicer.org/u/mahranahm)\
**Post date:** [August 8, 2022, 8:51pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/7 "2022-08-08T20:51:49Z")

</div>

So I ran the auto segmentation on a few volumes including the trained volumes and I seem to be getting the exact same result for all of them, The exact same segmentation like the one above.

Both the training and validation datasets are in NIFTI format

---

<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:** [August 9, 2022, 4:54am UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/8 "2022-08-09T04:54:24Z")

</div>

@diazandr3s could you have a look at this? Thank you.

---

<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:** [August 9, 2022, 2:28pm UTC](https://discourse.slicer.org/t/unexpected-results-from-training-new-model-in-monai-label/24681/9 "2022-08-09T14:28:59Z")

</div>

Many thanks for pinging me here, @rbumm - I haven’t seen this post.

@mahranahm welcome to the Slicer forum and thanks for posting this issue.

Could you please let us know which monai label version are you using?

If it is easy for you, I’d suggest you work directly with the GitHub repo. The reason for this is because it includes a more robust segmentation model called _[localization\_spine](https://github.com/Project-MONAI/MONAILabel/blob/main/sample-apps/radiology/lib/configs/localization_spine.py)_ - probably not the best name but I’m still working on this to make it generic 🙂

The only two changes you have to make to this model before training are to update the label names here: [MONAILabel/localization\_spine.py at main · Project-MONAI/MONAILabel · GitHub](https://github.com/Project-MONAI/MONAILabel/blob/main/sample-apps/radiology/lib/configs/localization_spine.py#L33-L58) - please don’t include background. you don’t need to segment it either.

And comment this line out: [MONAILabel/localization\_spine.py at main · Project-MONAI/MONAILabel · GitHub](https://github.com/Project-MONAI/MONAILabel/blob/main/sample-apps/radiology/lib/infers/localization_spine.py#L83)

Another question/comment is about the label numbering - have you checked that each segment in the database has the same number? i.e. the right lung should be represented by the same number in all volumes.

Hope this helps,
