Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle dimension issues #13

Open
wefwefWEF2 opened this issue Aug 10, 2023 · 1 comment
Open

How to handle dimension issues #13

wefwefWEF2 opened this issue Aug 10, 2023 · 1 comment

Comments

@wefwefWEF2
Copy link

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants