yhygao / CBIM-Medical-Image-Segmentation

A PyTorch framework for medical image segmentation
Apache License 2.0
272 stars 48 forks source link

Questions about prediction.py file #23

Closed haideralimughal closed 10 months ago

haideralimughal commented 1 year ago

Hi, I used a 3D Unet model with a 3D acdc dataset, successfully completed the training phase, saved the weights, and got the desired results. now, I am currently trying to obtain the inference results and visualization maps on the acdc testing set (testing set containing of patients information in 4d.nii) such as mentioned blew the setting of prediciton.py file....


parser.add_argument('--dataset', type=str, default='acdc', help='dataset name') parser.add_argument('--model', type=str, default='unet', help='model name') parser.add_argument('--dimension', type=str, default='3d', help='2d model or 3d model')

parser.add_argument('--load', type=parse_model_list, default='C:/Users/lenovo/PycharmProjects/CBIMM/exp/acdc/acdc_3d_unet/fold_4_latest.pth', help='the path of trained model checkpoint. Use \',\' as the separator if load multiple checkpoints for ensemble')
parser.add_argument('--img_path', type=str, default='C:/Users/lenovo/PycharmProjects/CBIMM/database/testing/patient101/', help='the path of the directory of images to be predicted')
parser.add_argument('--save_path', type=str, default='C:/Users/lenovo/PycharmProjects/CBIMM/Prediction_results/', help='the path to save predicted label')
parser.add_argument('--target_spacing', type=parse_spacing_list, default='1.0,1.0,1.0', help='the spacing that used for training, in x,y,z order for 3d, and x,y order for 2d')

Every time I started to execute the prediction.py file using the aforementioned settings, I was met with this problem. do we need any preprocessing for the testing set like we did it before the training phase for the training set ?

C:\Users\lenovo\anaconda3\envs\cbm\python.exe C:\Users\lenovo\PycharmProjects\CBIMM\prediction.py Loading configurations from config/acdc/unet_3d.yaml Model loaded from C:/Users/lenovo/PycharmProjects/CBIMM/exp/acdc/acdc_3d_unet/fold_4_latest.pth Traceback (most recent call last): File "C:\Users\lenovo\PycharmProjects\CBIMM\prediction.py", line 280, in tmp_itk_img.CopyInformation(itk_img) File "C:\Users\lenovo\anaconda3\envs\cbm\lib\site-packages\SimpleITK\SimpleITK.py", line 3113, in CopyInformation return _SimpleITK.Image_CopyInformation(self, srcImage) RuntimeError: Exception thrown in SimpleITK Image_CopyInformation: D:\a\1\sitk\Code\Common\src\sitkImage.cxx:227: sitk::ERROR: Source Image for information does not match this image's dimension.