-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
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
Inference made using detect.py differs than inference made using PyTorch Hub inference #6394
Comments
👋 Hello @edwardwang1, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available. For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com. RequirementsPython>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. 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 (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit. |
@edwardwang1 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. Your issue is not reproducible. Inference with detect.py and PyTorch Hub respectively for bus.jpg are below. If you are comparing both you should ensure all parameters are identical including batch size. 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:
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! 😃 |
Hi Glenn, Thanks for the prompt response. I tried the bus example using default yolov5x weights myself, and indeed found no discrepancy. It appears the issue is with my custom weights and custom classes. I will update if I am able to resolve this. |
I've determined that my issue was due to not specifying the image size when using PyTorch Hub inference. I previously didn't include the |
Search before asking
Question
I have noticed that the inference obtained through the detect.py script differs than the inference made using PyTorch Hub. At first, I thought the issue was due to a discrepancy between the model downloaded from PyTorch Hub and the local copy of the model. However, the issue persisted even when loading the local model. The model weights were generated using the train.py script. Essentially, the bounding box is tighter in the PyTorch Hub case than the detect.py case.
I found a similar issue here. #2224
Inference via detect.py
!python detect.py --img-size 288 --conf 0.01 --project /content/saveDir2/ --save-conf --save-txt --source /content/temptest/ --weights "./yolo50epoch288V2_best.pt"
results = model(image).pandas().xywhn[0]
Results (x_cent, y_cent, width, height, conf) = (0.13 0.43 0.25 0.27 0.80)
Inference via PyTorch Hub
model = torch.hub.load('ultralytics/yolov5', 'custom', path="./yolo50epoch288V2_best.pt", force_reload=True)
results = model(image).pandas().xywhn[0]
Inference via PyTorch Hub (Local)
model = torch.hub.load('.', 'custom', path="./yolo50epoch288V2_best.pt", source="local", force_reload=True)
results = model(image).pandas().xywhn[0]
Results (x_cent, y_cent, width, height, conf) = (0.13, 0.43, 0.15, 0.14, 0.59)
Environment
I am running everything in a Google Colab Environment
YOLOv5 🚀 2022-1-22 torch 1.10.0+cu111 CUDA:0 (Tesla T4, 15110MiB)
YOLOv5 install
!git clone https://github.com/ultralytics/yolov5.git
!mv ./yolov5/* ./
!pip install -r requirements.txt
The issue also persists on my local machine.
YOLOv5 v6.0-205-gbd815d4 torch 1.9.0 CUDA:0 (NVIDIA GeForce RTX 3080, 10240MiB)
Additional
No response
The text was updated successfully, but these errors were encountered: