med-air / 3DSAM-adapter

Holistic Adaptation of SAM from 2D to 3D for Promptable Medical Image Segmentation
134 stars 12 forks source link

How to handle dimension issues #13

Open wefwefWEF2 opened 11 months ago

wefwefWEF2 commented 11 months ago

Thanks a lot for your work,it helps a lot.

File "/code/medical/3dsam_adapter/3DSAM-adapter/modeling/Med_SAM/image_encoder.py", line 281, in forward x = x + pos_embed RuntimeError: The size of tensor a (10) must match the size of tensor b (32) at non-singleton dimension 3

here x #torch.Size([1, 32, 32, 10, 768]) and pos_embed #torch.Size([1, 32, 32, 32, 768]).

I didn't modify the code, but changed the training to parallel on 3 gpus . The result is the same for the colon and Pancreas data sets in the original paper. How can I solve it? Thank you very much.

peterant330 commented 11 months ago

Thanks a lot for your work,it helps a lot.

File "/code/medical/3dsam_adapter/3DSAM-adapter/modeling/Med_SAM/image_encoder.py", line 281, in forward x = x + pos_embed RuntimeError: The size of tensor a (10) must match the size of tensor b (32) at non-singleton dimension 3

here x #torch.Size([1, 32, 32, 10, 768]) and pos_embed #torch.Size([1, 32, 32, 32, 768]).

I didn't modify the code, but changed the training to parallel on 3 gpus . The result is the same for the colon and Pancreas data sets in the original paper. How can I solve it? Thank you very much.

It seems you are using a batch size of 1 with 3 GPUs, so the parallel mechanism divided a single image into three sub-image by the depth dimension. So that it no longer aligns with the rest of the network architecture.

If you want to use multiple GPUs, you should connect them sequentially rather than in parallel. You can put different blocks of the encoder into different GPUs and then move your intermediate variables among these GPUs. But make sure for each GPU the variables correspond to the entire image.