Project-MONAI / tutorials

MONAI Tutorials
https://monai.io/started.html
Apache License 2.0
1.85k stars 681 forks source link

Tutorial 3D Multi-organ Segmentation with UNETR (BTCV Challenge) - got problem with image's shape #640

Closed Yhe9718 closed 2 years ago

Yhe9718 commented 2 years ago

Hi, I tried to run the code(attached below) after loading the images but got an error with the dimension. I am wondering if the image's shape should be torch.Size([1, 220, 220, 45]).

Thank you

slice_map = { "img0035.nii.gz": 170, "img0036.nii.gz": 230, "img0037.nii.gz": 204, "img0038.nii.gz": 204, "img0039.nii.gz": 204, "img0040.nii.gz": 180, } case_num = 0 img_name = os.path.split(val_ds[case_num]["image_meta_dict"]["filename_or_obj"])[1] img = val_ds[case_num]["image"] label = val_ds[case_num]["label"] img_shape = img.shape label_shape = label.shape print(f"image shape: {img_shape}, label shape: {label_shape}") plt.figure("image", (18, 6)) plt.subplot(1, 2, 1) plt.title("image") plt.imshow(img[0, :, :, slice_map[img_name]].detach().cpu(), cmap="gray") plt.subplot(1, 2, 2) plt.title("label") plt.imshow(label[0, :, :, slice_map[img_name]].detach().cpu()) plt.show()

Nic-Ma commented 2 years ago

Hi @hy939251175 ,

Thanks for your interest here, could you please help provide the error message and full test program for further analysis? Then @ahatamiz may help provide more information about the expected data shape.

Thanks in advance.

ahatamiz commented 2 years ago

Hi @hy939251175 , would you please post the error message ? note that slice_map is only intended to select one slice of the entire 3D volume for visualization purposes only.

Thanks

Yhe9718 commented 2 years ago

Hi @Nic-Ma and @ahatamiz. thank you for your response. The error messages are as the following, and the code that I tried to run was unchanged from 3d_segmentation/unetr_btcv_segmentation_3d.ipynb

Many thanks

image shape: torch.Size([1, 220, 220, 45]), label shape: torch.Size([1, 220, 220, 45])

KeyError Traceback (most recent call last) in () 17 plt.subplot(1, 2, 1) 18 plt.title("image") ---> 19 plt.imshow(img[0, :, :, slice_map[slice_map[img_name]]].detach().cpu(),cmap="gray") 20 plt.subplot(1, 2, 2) 21 plt.title("label")

KeyError: 170