# MonaiLabel internal server error when running the model

**URL:** <https://discourse.slicer.org/t/monailabel-internal-server-error-when-running-the-model/42578>\
**Category:** Support\
**Tags:** monai, monailabel\
**Created:** [April 15, 2025, 6:59pm UTC](https://discourse.slicer.org/t/monailabel-internal-server-error-when-running-the-model/42578 "2025-04-15T18:59:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chz31](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chz31/32/77363_2.png) [@chz31](https://discourse.slicer.org/u/chz31)\
**Post date:** [April 15, 2025, 6:59pm UTC](https://discourse.slicer.org/t/monailabel-internal-server-error-when-running-the-model/42578/1 "2025-04-15T18:59:36Z")

</div>

Hi,

I successfully trained a model using MonaiLabel for a simple skull segmentation. However, when I tested running the model on a volume, it reported `Status: 500; Response: Internal Server Error`

```auto
Traceback (most recent call last):
  File "C:/ProgramData/slicer.org/Slicer 5.8.0/slicer.org/Extensions-33216/MONAILabel/lib/Slicer-5.8/qt-scripted-modules/MONAILabel.py", line 1565, in onClickSegmentation
    result_file, params = self.logic.infer(model, image_file, params, session_id=self.getSessionId())
  File "C:/ProgramData/slicer.org/Slicer 5.8.0/slicer.org/Extensions-33216/MONAILabel/lib/Slicer-5.8/qt-scripted-modules/MONAILabel.py", line 2397, in infer
    result_file, params = client.infer(model, image_in, params, label_in, file, session_id)
  File "C:\ProgramData\slicer.org\Slicer 5.8.0\slicer.org\Extensions-33216\MONAILabel\lib\Slicer-5.8\qt-scripted-modules\MONAILabelLib\client.py", line 344, in infer
    raise MONAILabelClientException(
MONAILabelLib.client.MONAILabelClientException: (1, 'Status: 500; Response: Internal Server Error')

```

I used the deepedit model. The only modification I did was simply changing the labels in deepedit.py to

```auto
self.labels = {
            "skull": 1,
            "background": 0,
        }

```

I also saved the model script as `deepedit_skull.py.`

I could train and run the default deepedit model to segment a new abdominal volume with no problem.

Here is the full log of the Slicer session: [Slicer\_5.8.0\_33216\_20250415\_124050\_526.log - Google Drive](https://drive.google.com/file/d/1g2NypYBYqVZUxdcR0s4hIvirIODwEmy_/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [April 16, 2025, 1:55am UTC](https://discourse.slicer.org/t/monailabel-internal-server-error-when-running-the-model/42578/2 "2025-04-16T01:55:54Z")

</div>

@chz31 given that you are using 5.8.0, I would first suggest trying with the latest preview or the stable (5.8.1) to rule out issues that might have been already fixed.

---

<div class="post-metadata">

**Author:** ![chz31](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chz31/32/77363_2.png) [@chz31](https://discourse.slicer.org/u/chz31)\
**Post date:** [April 16, 2025, 3:56am UTC](https://discourse.slicer.org/t/monailabel-internal-server-error-when-running-the-model/42578/3 "2025-04-16T03:56:06Z")

</div>

@muratmaga Thanks! I found the reason was because I still used the pretrained deepedit model, so it expected 9 labels instead of 2:

```auto
"C:\Users\chi.zhang\AppData\Local\anaconda3\envs\monai_py39\lib\site-packages\torch\nn\modules\module.py", line 2581, in load_state_dict
    raise RuntimeError(
RuntimeError: Error(s) in loading state_dict for DynUNet:
        size mismatch for input_block.conv1.conv.weight: copying a param with shape torch.Size([32, 9, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([32, 3, 3, 3, 3]).
        size mismatch for input_block.conv3.conv.weight: copying a param with shape torch.Size([32, 9, 1, 1, 1]) from checkpoint, the shape in current model is torch.Size([32, 3, 1, 1, 1]).
        size mismatch for output_block.conv.conv.weight: copying a param with shape torch.Size([8, 32, 1, 1, 1]) from checkpoint, the shape in current model is torch.Size([2, 32, 1, 1, 1]).
        size mismatch for output_block.conv.conv.bias: copying a param with shape torch.Size([8]) from checkpoint, the shape in current model is torch.Size([2]).
        size mismatch for skip_layers.downsample.conv1.conv.weight: copying a param with shape torch.Size([32, 9, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([32, 3, 3, 3, 3]).
        size mismatch for skip_layers.downsample.conv3.conv.weight: copying a param with shape torch.Size([32, 9, 1, 1, 1]) from checkpoint, the shape in current model is torch.Size([32, 3, 1, 1, 1]).

```

I followed the instruction here [Error while Training from scratch · Project-MONAI/MONAILabel · Discussion #1252 · GitHub](https://github.com/Project-MONAI/MONAILabel/discussions/1252#discussioncomment-4758944) to specify `--conf use_pretrained_model false` and removed the pt files in radiology/model. It worked now.
