MONAILabel icon indicating copy to clipboard operation
MONAILabel copied to clipboard

MonaiLabel Segmentation Error

Open brchck opened this issue 1 year ago • 3 comments

I am trying to train a new dataset (8 bit with 14 channels) within slicer via the MonaiLabel extension. I have adjusted the segmentation config to contain the correct parameters.

All the images and labels are loading fine. Not sure what other information is needed - any questions please leave a comment and I'll reply ASAP

This is the metadata from the images NRRD0005 This NRRD file was generated by pynrrd on 2023-07-04 00:07:44(GMT). Complete NRRD file format specification at: http://teem.sourceforge.net/nrrd/format.html type: uint8 dimension: 3 sizes: 225 285 400 encoding: gzip

Here is the error: weird_err_msg_monai.txt

brchck avatar Jul 25 '23 10:07 brchck

Hi @brchck,

Thanks for opening this issue. Which format are the volumes (i.e. NRRD. NIfTI)? It seems at least one volume has header issues or you are using thw wrong reader. From the logs I can see this:

  File "/g/data/if89/apps/monailabel/0.7.0/lib/python3.9/site-packages/monai/data/image_reader.py", line 1339, in _get_affine
    direction = img.header["space directions"]
KeyError: 'space directions'
The above exception was the direct cause of the following exception:

this is the reader method getting the affine from the headers: https://github.com/Project-MONAI/MONAI/blob/2800a76764bc2f58402718fcef8b38f3a60776d0/monai/data/image_reader.py#L1330-L1347

If images are in .nii.gz or .nii format, consider using the itkreader instead (https://github.com/Project-MONAI/MONAI/blob/2800a76764bc2f58402718fcef8b38f3a60776d0/monai/data/image_reader.py#L151). Otherwise I'd suggest you check the volume headers. There might be an issue there.

Hope this helps,

diazandr3s avatar Jul 25 '23 18:07 diazandr3s

It seems that your image lacks essential metadata: image origin and spacing. These fields are optional, but practically they are mandatory because if they are not defined then your image will not appear in the correct position and orientation, so reporting an error if they are not defined makes sense.

These are the fields that are missing from your header:

space directions: (0.76171898841857932,0,0) (0,0.76171898841857932,0) (0,0,2.5)
space origin: (-195.00000000000003,-171.69999694824224,-347.75000000000011)

Usually you can copy these fields from the input image.

lassoan avatar Jul 26 '23 17:07 lassoan

Hi all,

I made a pull request: #1505. This is a just a function that I made in util/others that would init the origin and direction in images without that information.

We use a modified version of MPI/LAMA (a mouse embryo registration pipeline) and part of the pre-processing is to remove spacing, orientation and directional information.

It might be a bit far fetched but do think it is possible to do a quick check of the first img's header, then call the function if it's missing info.

Kind Regards, Kyle

dorkylever avatar Jul 27 '23 06:07 dorkylever