ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.48k stars 16.29k forks source link

RuntimeError: Sizes of tensors must match except in dimension 2. Got15 and 16(The offending index is 0) #1237

Closed zorro2017zdc closed 3 years ago

zorro2017zdc commented 4 years ago

❔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. image image

github-actions[bot] commented 4 years ago

Hello @zorro2017zdc, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

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.

glenn-jocher commented 3 years ago

@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:

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!

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.6. To install run:

$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If 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.

github-actions[bot] commented 3 years ago

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.

AilvenLiu commented 3 years ago

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.

Radleye commented 3 years ago

I met same problem, who solve it

glenn-jocher commented 3 years ago

@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:

CODE TO REPRODUCE YOUR ISSUE HERE


- **Your custom data.** If your issue is not reproducible in one of our 3 common datasets ([COCO](https://github.com/ultralytics/yolov5/blob/master/data/coco.yaml), [COCO128](https://github.com/ultralytics/yolov5/blob/master/data/coco128.yaml), or [VOC](https://github.com/ultralytics/yolov5/blob/master/data/voc.yaml)) we can not debug it. Visit our [Custom Training Tutorial](https://docs.ultralytics.com/yolov5/tutorials/train_custom_data) for guidelines on training your custom data. Examine `train_batch0.jpg` and `test_batch0.jpg` for a sanity check of your labels and images.

- **Your environment.** If your issue is not reproducible in one of the verified environments below we can not debug it. If you are running YOLOv5 locally, verify your environment meets all of the [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) dependencies specified below. If in doubt, download Python 3.8.0 from https://www.python.org/, create a new [venv](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/), and install requirements.

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](https://docs.ultralytics.com/help/minimum_reproducible_example/) of your issue. Thank you!

## Requirements

Python 3.8 or later with all [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) dependencies installed, including `torch>=1.7`. To install run:
```bash
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If 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.

HoseinHasani commented 3 years ago

I have the same problem, please help! The model works fine only if I use 640x640 images (I trained the model with 300x300 size)!

glenn-jocher commented 3 years ago

@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 Example

When 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! πŸ˜ƒ

juny7878 commented 2 years ago

@glenn-jocher. No more useless comments. plz

suzijun commented 2 years ago

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) RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 14 but got size 13 for tensor number 1 in the list.

glenn-jocher commented 2 years ago

@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.

Screenshot 2022-05-19 at 15 08 01

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 Example

When 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! πŸ˜ƒ

suzijun commented 2 years ago

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.

glenn-jocher commented 2 years ago

@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.

Screenshot 2022-05-19 at 15 37 52
qingtianwu commented 2 years ago

I met same problem, who solve it

+1

gerrylwk commented 1 year ago

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!

glenn-jocher commented 11 months ago

@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!