MHubAI / models

Stores the MHub models dockerfiles and scripts.
MIT License
8 stars 16 forks source link

Converting nifti to dicom-seg fails silently when referenced series is not fully DICOM compliant #105

Open vanossj opened 1 week ago

vanossj commented 1 week ago

This problem came up from this issue when I tried to run the bamf_nnunet_ct_kidney model on a ct scan from TCGA-KIRC.

The issue is with series 1.3.6.1.4.1.14519.5.2.1.6450.4004.318185778053926832345567953536, you can reproduce the issue with the code below.

Download the series from the IDC

from idc_index import index
from pathlib import Path

Path("example_data").mkdir(exist_ok=True)

client = index.IDCClient()
client.download_from_selection(
    seriesInstanceUID=["1.3.6.1.4.1.14519.5.2.1.6450.4004.318185778053926832345567953536"],
    downloadDir="example_data",
)

Run the bamf_nnunet_ct_kidney model

mkdir example_output
export in=$(pwd)/example_data
export out=$(pwd)/example_output

docker run --rm -t --gpus all -v $in:/app/data/input_data -v $out:/app/data/output_data mhubai/bamf_nnunet_ct_kidney

On my system it took about 12 minutes to run. Then finished with no warnings or errors, but the example_output directory was empty.

@jithenece dug in a bit and found that itkimage2segimage is reporting an error with the CT scan not being compliant with the dicom standard. He went into the container and ran itkimage2segimage --inputImageList VOLUME_001.nii.gz --inputDICOMDirectory dicom --outputDICOM seg.dcm --inputMetadata temp-meta.json

which gave the output:

DEBUG - Writing per-frame group: Frame Content Functional Group Macro for frame #65
DEBUG - Writing per-frame group: Plane Position (Patient) Functional Group Macro for frame #65
DEBUG - Writing per-frame group: Segmentation Functional Group Macro for frame #65
DEBUG - Writing component: DimensionOrganizationSequence
DEBUG - Writing component: DimensionIndexSequence
DEBUG - Writing component: DimensionIndexSequence
DEBUG - Writing component: MultiframeDimensionModule
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: CodeSequenceMacro
DEBUG - Writing component: SOPCommonModule
DEBUG - Writing component: PatientModule
DEBUG - Writing component: PatientStudyModule
DEBUG - Writing component: HL7HierarchicDesignatorMacro
DEBUG - Writing component: CodeSequenceMacro
ERROR - CodingSchemeDesignator (0008,0102) absent in CodeSequenceMacro (type 1)
ERROR - Could not write item #0 in ProcedureCodeSequence: Missing Attribute(s)
FATAL ERROR: Writing of the SEG dataset failed! Error: Missing Attribute(s). Please report the problem to the developers, ideally accompanied by a de-identified dataset allowing to reproduce the problem!
ERROR: Conversion failed.

I did run into these issues when working on AIMI, my solution was just to smash the referenced dicom into some sort of compliance so that itkimage2segimage would generate the segmentation image.

This is the script I used to fix various dicom issues I came across as I worked on AIMI, but I would hope there is a better alternative somewhere out there for fixing dicom files.

It would be useful to have the DsegConverter step report the error

LennyN95 commented 1 week ago

Thank you for the detailed report! We have a cli argumen --stop-on-error which will halt execution if an error occurs (in combination with --print the error message is routed to the stdout instead of the log files).

How we'll deal with incompliant dicom files could lead to an interesting discussion where I can see multiple strategies:

LennyN95 commented 1 week ago

@fedorov

fedorov commented 1 week ago

It's a known issue, unfortunately - related to https://github.com/QIICR/dcmqi/issues/232.