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

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 16 but got size 32 for tensor number 1 in the list. #12923

Closed
2 tasks done
zhangsanliisi opened this issue Apr 15, 2024 · 2 comments
Labels
bug Something isn't working Stale

Comments

@zhangsanliisi
Copy link

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

No response

Bug

When i add "CA" to v5-7.0, segment , i want add CA to .yaml backbone each C3 end, when i train , begin:
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 16 but got size 32 for tensor number 1 in the list.

Environment

Traceback (most recent call last):
File "D:/YOLO/yolov5-v7.0/models/yolo.py", line 377, in
model = Model(opt.cfg).to(device)
File "D:/YOLO/yolov5-v7.0/models/yolo.py", line 195, in init
m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))]) # forward
File "D:/YOLO/yolov5-v7.0/models/yolo.py", line 194, in
forward = lambda x: self.forward(x)[0] if isinstance(m, Segment) else self.forward(x)
File "D:/YOLO/yolov5-v7.0/models/yolo.py", line 209, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "D:/YOLO/yolov5-v7.0/models/yolo.py", line 121, in _forward_once
x = m(x) # run
File "D:\Anaconda\envs\yolov5-7.0\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "D:\YOLO\yolov5-v7.0\models\common.py", line 313, in forward
return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 16 but got size 32 for tensor number 1 in the list.

Process finished with exit code 1

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@zhangsanliisi zhangsanliisi added the bug Something isn't working label Apr 15, 2024
@glenn-jocher
Copy link
Member

Hello! It looks like you're encountering a tensor size mismatch error when trying to integrate CA (Channel Attention, I'm guessing?) into the YOLOv5 model. This often happens due to incompatible feature map sizes when concatenating or merging layers.

A common cause for this issue is when the dimensions of the feature maps don't align due to different strides, paddings, or kernel sizes upstream in your network modifications. Ensure the CA module you're integrating outputs a tensor that matches the expected dimensions for concatenating with the backbone's feature map at that point.

For example, if you're adding a CA module after a C3 block, double-check:

  1. The output size of the C3 block.
  2. The expected input size of the layer following your CA module.
  3. Adjust the CA module accordingly to ensure the output size matches the expected input size of the subsequent layer.

Without specific details of your CA implementation, a generic suggestion would be to review and match the output dimensions of your CA module to the input requirements of the subsequent layers. This may involve adjusting kernel sizes, strides, or paddings in your CA module or adapting the merging strategy.

Keep exploring and tweaking — the YOLOv5 architecture is quite flexible, and custom enhancements like yours contribute to the community's growth! If you continue to experience issues, consider providing a snippet of how you're integrating CA into the model for more targeted advice. Good luck! 🚀

Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label May 16, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants