MIC-DKFZ / nnUNet

Apache License 2.0
5.79k stars 1.74k forks source link

Axis ordering revision while apply pre-trained model to custom dataset #1167

Closed joeyzyz closed 2 years ago

joeyzyz commented 2 years ago

It is critically important that the scans you are predicting have the same axis ordering than nnU-Net. What I mean by this is that when you open up the images with sitk or nibabel and export the numpy arrays, the axes need to match (for example the first coordinate should always be axial slices, so a[12] is the axial slice id 12). If they don't the performance can degrade a lot. I did run into this issue myself when I was applying KiTS to some internal CT data.

Originally posted by @FabianIsensee in https://github.com/MIC-DKFZ/nnUNet/issues/277#issuecomment-663984088

Hi, @FabianIsensee

Thanks for your reply in the above issue 277, I have a more detailed question concerning with this issue.

You said you also had the axis ordering mismatch problem while apply KiTS model to other dataset, I am wondering:

  1. how did you fix it, that is, how to revise the code in preprocessing data?
  2. I got the solution by referring to here, It can be illustrated with one line of code: canonical_img = nib.as_closest_canonical(img), but it turned out not working, could you share me with your solution?

Thank you very much~

FabianIsensee commented 2 years ago

Hi, you just play around with the images until the numpy arrays have the same orientation. Make sure to transpose the spacing along with the image!