-
-
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
custom model inference without using detect.py #6460
Comments
👋 Hello @memelvin99, 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 support@ultralytics.com. RequirementsPython>=3.7.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. |
@memelvin99 👋 Hello! Thanks for asking about handling inference results. YOLOv5 🚀 PyTorch Hub models allow for simple model loading and inference in a pure python environment without using Simple Inference ExampleThis example loads a pretrained YOLOv5s model from PyTorch Hub as import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, etc.
# model = torch.hub.load('ultralytics/yolov5', 'custom', 'path/to/best.pt') # custom trained model
# Images
im = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, URL, PIL, OpenCV, numpy, list
# Inference
results = model(im)
# Results
results.print() # or .show(), .save(), .crop(), .pandas(), etc.
results.xyxy[0] # im predictions (tensor)
results.pandas().xyxy[0] # im predictions (pandas)
# xmin ymin xmax ymax confidence class name
# 0 749.50 43.50 1148.0 704.5 0.874023 0 person
# 2 114.75 195.75 1095.0 708.0 0.624512 0 person
# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie See YOLOv5 PyTorch Hub Tutorial for details. Good luck 🍀 and let us know if you have any other questions! |
Thanks for the quick reply. I have trained a custom model and saved best.pt locally. Here is the complete code:
|
The above colab sample code is working for me. But the issue is when I am loading my custom model locally. I am getting error:
I have also tried |
model = torch.hub.load('../yolov5/','custom',path='Yourpath/best.pt',source='local'). |
@memelvin99 your code is out of date |
I'm getting the same error with a similar setup. If the code is out of date, what is the correct way to do this? I'm pulling the line of code from the official tutorials for yolov5. Edit: for additional clarity, I am running locally on Windows 10, and I am using PyTorch with CUDA. Detect.py works perfectly, but for my use case I am going to need to write my own code, and it keeps failing. |
@Thebombuknow error has been fixed earlier in #6461. To receive this update:
Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀! |
Thanks! That fixed it! I just got extremely unlucky, as I happened to pull the repo mere hours before the bug was fixed. |
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Access additional YOLOv5 🚀 resources:
Access additional Ultralytics ⚡ resources:
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 YOLOv5 🚀 and Vision AI ⭐! |
Hi @glenn-jocher, I have been following your instructions above to get the best results for the custom model. Can you help me understand what is happening within the error prompt and how do I proceed to solve this challenge? WHEN I: try it this way it works: BUT I would like to get the results printed xmin ymin xmax ymax confidence class nameMy code:
|
@Symbadian you don't load yamls, you load models, i.e. model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, etc.
model = torch.hub.load('ultralytics/yolov5', 'custom', 'path/to/best.pt') # custom trained model |
Hi @glenn-jocher, I tried that as well and got the same error hence me reaching out to you... I also tried:
please assist!?
|
@Symbadian just read your error and fix this yourself. It says unexpected indent. This is user error. |
Hi @glenn-jocher and thanks so much for your swift response and your time, I really really appreciate this.. I am trying to interpret these errors so I realized that there was an indentation error so I fixed it, but that was not the real issue, and I tried yours to see if it would the model from the link automatically, but that did not work as well..
please see below forgive my persistence but I am really really trying to get this right
|
@Symbadian I've already told you above not to load YAMLs. Please don't waste my time, I'm extremely busy. |
forgive my lapse in understanding @glenn-jocher, I am really trying to get this going, please see below:
|
It is not working. Can you please look into it. |
@ashishupadhyaa hello! Thank you for reaching out and sharing your concern about the YOLOv5 PyTorch Hub model. I apologize for the inconvenience you are facing. To better assist you, could you please provide more details about the specific issue you are encountering? Are you experiencing any error messages or unexpected behavior? Once we have more information, we will be able to investigate the issue and provide a solution or further guidance. Looking forward to hearing from you. |
Search before asking
Question
Hi,
I would like to use a custom inference code other than "detect.py". Here is the code I am trying, but not working.
Additional
No response
The text was updated successfully, but these errors were encountered: