-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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 2. Got15 and 16(The offending index is 0) #1237
Comments
Hello @zorro2017zdc, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:
For more information please visit https://www.ultralytics.com. |
@zorro2017zdc I just tested your changes and started training and everything works correctly. I'm just going to link our default reply here: Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:
sudo rm -rf yolov5 # remove existing
git clone https://github.com/ultralytics/yolov5 && cd yolov5 # clone latest
python detect.py # verify detection
# CODE TO REPRODUCE YOUR ISSUE HERE
If none of these apply to you, we suggest you close this issue and raise a new one using the Bug Report template, providing screenshots and minimum viable code to reproduce your issue. Thank you! RequirementsPython 3.8 or later with all requirements.txt dependencies installed, including $ pip install -r requirements.txt EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I meet the same problem when I using yolov5's detect.py to detect Scaled YOLOv4. When I resize the img_shape to hava same width and height, it runs. However, train.py without any problem. It seems some of models can only run with images having equal w and h. |
I met same problem, who solve it |
@xiaowo1996 👋 Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:
$ git clone https://github.com/ultralytics/yolov5 yolov5_new # clone latest
$ cd yolov5_new
$ python detect.py # verify detection
# CODE TO REPRODUCE YOUR ISSUE HERE
If none of these apply to you, we suggest you close this issue and raise a new one using the 🐛 Bug Report template, providing screenshots and a minimum reproducible example of your issue. Thank you! RequirementsPython 3.8 or later with all requirements.txt dependencies installed, including $ pip install -r requirements.txt EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu. |
I have the same problem, please help! |
@HoseinHasani 👋 hi, thanks for letting us know about this problem with YOLOv5 🚀. We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem. How to create a Minimal, Reproducible ExampleWhen asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
In addition to the above requirements, for Ultralytics to provide assistance your code should be:
If you believe your problem meets all of the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template and providing a minimum reproducible example to help us better understand and diagnose your problem. Thank you! 😃 |
@glenn-jocher. No more useless comments. plz |
i have the same problem when i use yolov5 l6。I just can set the image size 640 to val or detect my image。other size are the problem that ------ return torch.cat(x, self.d) |
@suzijun @HoseinHasani 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. YOLOv5l6 inference runs correctly at any image size. Your issue in not reproducible. We've created a few short guidelines below to help users provide what we need in order to start investigating a possible problem. How to create a Minimal, Reproducible ExampleWhen asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
For Ultralytics to provide assistance your code should also be:
If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem. Thank you! 😃 |
Thank your reply,The image size I input can only be a multiple of 64. I don't know whether it is related to the step size of the model. I have visualized that the step size of Yolol6 is 64 while that of L is 32 So when I use yoloV5 L model input 416 image size detection is no problem. |
@suzijun yes all models have stride constraints, P5 = 2 ** 5 = 32, P6 = 2 ** 6 = 64 etc. This is a fundamental property of all object detection models in AI. In any case YOLOv5 automatically handles incorrect sizes, so I have no idea how you are producing errors. As I said please supply a minimum reproducible example. |
+1 |
Faced the same issue. The fix is to resize the image such that the image that is fed into the forward pass of the model should be suitable for the YOLOv5 architecture that you're using. E.g. For YOLOv5s, v5n, v5m, v5l, v5x, you should be using 640x640 images. Hope this helps! |
@gerrylwk thanks for lending a hand and providing a workaround for the issue! It's important to ensure that the input image size aligns with the specific YOLOv5 architecture being used. If anyone else is encountering this, resizing the image to adhere to the requirements of the YOLOv5 architecture being utilized should resolve the problem. Great insight! |
❔Question
I set image_size (320,320), origin image_size 600x450.
I used yolov5s.yaml , no problem. but when I changed yolov5s.yaml.
During training work , test work get following error.
RuntimeError: Sizes of tensors must match except in dimension 2.Got15 and 16(The offending index is 0)
Additional context
I changed yolov5s.yaml like this.


The text was updated successfully, but these errors were encountered: