MIC-DKFZ / nnDetection

nnDetection is a self-configuring framework for 3D (volumetric) medical object detection which can be applied to new data sets without manual intervention. It includes guides for 12 data sets that were used to develop and evaluate the performance of the proposed method.
Apache License 2.0
553 stars 97 forks source link

[Question] Regarding image and label resolution and spacing #173

Closed yl3639 closed 10 months ago

yl3639 commented 1 year ago

:question: Question

Hi, May I ask is the spacing a issue when running nndet_prep and nndet_train

Say I have image with resolution(500, 500, 200) and spacing is (0.4, 0.4, 0.4). But my label is the same resolution as image which is (500, 500, 200) but spacing is (1.0, 1.0, 1.0).

Is this a problem for preparation and training? Thanks a lot!

mibaumgartner commented 1 year ago

Hey,

yes this is a problem and also quit curious since the resolution is the same while the spacing isn't. nnDetection expects that the resolution and spacing between the images and labels is the same. When running the preprocessing with the full check option and error should be raised.

Best, Michael

yl3639 commented 1 year ago

Hi, I trained with different spacing and there was no errors and the results make sense, should I train using same spacing? Thanks!

yl3639 commented 1 year ago

Hi, Also can I add another channel to the input, say originally i use CT image as the input(1 channel), now I hope to add one more vessel segmentation(mask) channel to make input 2 channels. Thanks!

mibaumgartner commented 1 year ago

Hi,

1) I'm not sure how your labels correspond to your images since the resolution (i.e. the number of pixels along the axis) is the same but the spacing is different. nnDetection expects that the pixels between the image and label correspond to each other (i.e. same resolution and same spacing, orientation etc.). Without the option nnDetection does not perform an explicit check (will be the default in future versions though).

2) You could create a new dataset where the second input channel is the segmentation. It is not possible to add channels post hoc since the data needs to be preprocessed. Also you might consider extending the following line: https://github.com/MIC-DKFZ/nnDetection/blob/98eb97f15d9f9d107fac11d27c153e18932ab635/nndet/planning/experiment/base.py#L278-L285 with a no-norm or raw option and map it to "raw" so the new channel (which is a segmentation) is not specifically normalised. Otherwise an intensity normalisation will be applied to it.

Best, Michael

yl3639 commented 1 year ago

Hi,

  1. I'm not sure how your labels correspond to your images since the resolution (i.e. the number of pixels along the axis) is the same but the spacing is different. nnDetection expects that the pixels between the image and label correspond to each other (i.e. same resolution and same spacing, orientation etc.). Without the option nnDetection does not perform an explicit check (will be the default in future versions though).
  2. You could create a new dataset where the second input channel is the segmentation. It is not possible to add channels post hoc since the data needs to be preprocessed. Also you might consider extending the following line: https://github.com/MIC-DKFZ/nnDetection/blob/98eb97f15d9f9d107fac11d27c153e18932ab635/nndet/planning/experiment/base.py#L278-L285 with a no-norm or raw option and map it to "raw" so the new channel (which is a segmentation) is not specifically normalised. Otherwise an intensity normalisation will be applied to it.

Best, Michael

Hi, Thanks for help! I made changes as followed and is it right?

image image
yl3639 commented 1 year ago

Besides, may I ask how can I build my own preprocessing pipeline? Say I have a new test data case, it's not convenient to run nndet_prep TaskName every-time, instead I just run my own preprocessing code with test_case.nii.gz as input and then the output(preprocessed result) could be feed into the model to do prediction. Thanks!

mibaumgartner commented 1 year ago

nndet_prep is only required if training data or test labels need to be prepared. For running inference on individual cases 'nndet_prep' is not necessary and simply running 'nndet_predict' will automatically preprocess and predict the cases. The function which is called for preprocessing there is located here: https://github.com/MIC-DKFZ/nnDetection/blob/98eb97f15d9f9d107fac11d27c153e18932ab635/nndet/planning/experiment/base.py#L398-L446

yl3639 commented 1 year ago

Hi, May I ask for the case.npz files stored at the /path/to/TaskXXX_XXX/preprocessed/D3V001_3d, in imagesTr, it contains 'data' and 'seg', what does the value mean in npz['seg'] at imagesTr while they all only contain value 0 and 1 in labelsTr/_seg_gt.npz? Because i find unique values in imagesTr npz like this:

image
mibaumgartner commented 1 year ago

The -1 value indicates certain regions from the preprocessing and will be removed before training. 0 is background. Everything above 0 indicates different objects, i.e. in the second segmentation with values [-1, 0, 1, 2] two objects are present.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 10 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.