MonaiLabel internal server error when running the model

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

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

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

@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.

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

"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 to specify --conf use_pretrained_model false and removed the pt files in radiology/model. It worked now.

1 Like