-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
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
AssertionError: input size torch.Size([1, 3, 640, 480]) not equal to max model size (1, 3, 640, 640) #12282
Comments
👋 Hello @KnightInsight, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. RequirementsPython>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started: git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install 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 currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit. Introducing YOLOv8 🚀We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀! Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects. Check out our YOLOv8 Docs for details and get started with: pip install ultralytics |
@KnightInsight this issue seems to occur when loading the exported TensorRT engine model using To address this issue, you can try resizing your input images to have a shape of If you still encounter any problems or have further questions, please feel free to ask. The YOLOv5 community and the Ultralytics team are here to assist you. |
When resizing an image, it can change the original size, possibly distorting the aspect ratio and making it challenging to detect objects accurately. However, in the detect.py script, the image is temporarily resized for processing, but the output image maintains the original size. Can torch.hub.load() be used in a same way in detect.py to achieve this behavior? |
@KnightInsight yes, you can achieve a similar behavior as the detect.py script when using Here's an example of how you can modify your code to achieve this: import torch
import torchvision.transforms as transforms
# Load the model
model = torch.hub.load('.', 'custom', 'yolov5s.engine', source='local')
# Resize the input image while maintaining aspect ratio
image_path = 'path/to/your/image.jpg'
image = Image.open(image_path)
image_transform = transforms.Resize((640, 640))
resized_image = image_transform(image)
# Perform object detection on the resized image
results = model([resized_image])
# Resize the output image back to the original size
output_image = transforms.Resize(image.size)(results.imgs[0])
# Continue with the rest of your code By following this approach, you can resize the input image while preserving the aspect ratio, perform object detection on the resized image, and finally resize the output image back to the original size. Hope this helps! If you have any additional questions or concerns, please let me know. |
However, the bounding box coordinates are different since it used the resized_image. How can I get the bounding box coordinates of original_image? I would like to print(results.xyxy[0]). |
To get the bounding box coordinates of the original image, you can use the
This code snippet will plot the bounding box coordinates on the original image and display it. Please note that the Let me know if you have any further questions or need any additional assistance. Glenn Jocher |
Hi, I have tested on the below code that you provided. However, I realized the accuracy of the detection getting lower during torch.hub.load. I have tested on detect.py but the accuracy maintained good. May I know what is the difference? Is detect.py not using transforms.Resize method? Besides, the inference time on detect.py(5ms) but torch.hub.load takes more than 50ms (not consistent too, can be 50ms,70ms,or 120ms), the inference range is large, hardware should not be the main issue to cause the spike, why? image_transform = transforms.Resize((640, 640)) Perform object detection on the resized imageresults = model([resized_image]) Thank you!!! |
When using the
To get consistent performance and accuracy with I hope this helps in addressing the performance differences you are observing. If you have further questions or concerns, feel free to ask. Glenn Jocher |
👋 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 ⭐ |
May I ask, does YOLOv8n-seg.engine use the above method as well? |
@KXHH2021 no, YOLOv8 uses the |
👋 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 ⭐ |
Search before asking
Question
Hi, I trained a yolov5s model and exported to tensorrt engine file by typing "python export.py --weights /yolov5s.pt --include engine --device 0". The engine model is 640x640. I tried to load multiple images with different image size(not 640x640) using detect.py script. It's worked even though input size is not 640x640. However, I tested on "model = torch.hub.load('.', 'custom', 'yolov5s.engine', source='local')" then AssertionError: input size torch.Size([1, 3, 640, 480]) not equal to max model size (1, 3, 640, 640).
Additional
No response
The text was updated successfully, but these errors were encountered: