Project-MONAI / MONAI

AI Toolkit for Healthcare Imaging
https://monai.io/
Apache License 2.0
5.85k stars 1.08k forks source link

EinopsError: Error while computing Rearrange #4100

Closed ouyuxuanbridge closed 2 years ago

ouyuxuanbridge commented 2 years ago

Hi,

when I am applying UNETR to my own dataset, which is (64,64,64)

there is an error occurred, I don't know how to fix it.

Could you please help me with it? Many Thanks

EinopsError: Error while computing Rearrange('b c (h p1) (w p2) (d p3) -> b (h w d) (p1 p2 p3 c)', p1=16, p2=16, p3=16) Shape mismatch, can't divide axis of length 43 in chunks of 16

ouyuxuanbridge commented 2 years ago

when the image is (80, 80, 80)

EinopsError: Error while computing Rearrange('b c (h p1) (w p2) (d p3) -> b (h w d) (p1 p2 p3 c)', p1=16, p2=16, p3=16) Shape mismatch, can't divide axis of length 54 in chunks of 16

Nic-Ma commented 2 years ago

Hi @ahatamiz ,

Could you please help share some comments about this Einops question?

Thanks in advance.

ahatamiz commented 2 years ago

Hi @Ouyuxuan623

If the UNETR image size is set to (64,64,64), you need to make sure that the image size in the data loader is the same (64,64,64). For example, when using RandCropByPosNegLabeld, you need to make sure the spatial size is correctly set up. For example:

monai.transforms.RandCropByPosNegLabeld(
                keys=["image", "label"],
                label_key="label",
                spatial_size=(64, 64, 64),
                pos=1,
                neg=1,
                num_samples=4,
                image_key="image",
                image_threshold=0,
            )

The image size of (80,80,80) is not divisible by (16,16,16) which is the patch size in UNETR, and hence patch embedding cannot be done. This condition is strictly enforced here.