-
-
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
Image Inference from memory #2694
Comments
👋 Hello @DrewDaPilot, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com. 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 currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit. |
@DrewDaPilot yes, you can pass various different media formats directly to YOLOv5 PyTorch Hub models for inference, including of course images already loaded into memory. See PyTorch Hub Tutorial for details Lines 238 to 247 in 9ccfa85
YOLOv5 Tutorials
|
Thanks for the reply. I tried what you suggested and I get a strange error.
'import torch model = torch.hub.load('ultralytics/yolov5', 'yolov5s') @app.route('/upload', methods=['POST']) |
@DrewDaPilot thanks for the bug report. This is a duplicate issue of #2702 which was also raised today, and is caused by PIL Image objects lacking filenames. We should have a fix for this later today. |
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. |
import torch
import d3dshot
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
d = d3dshot.create()
img = d.screenshot()
# Image
# img = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg' # batched list of images
# Inference
results = model(img)
# Results
results.print()
results.show() # or .show()
# Data
print(results.pandas().xyxy[0]) # print img1 predictions (pixels)
# x1 y1 x2 y2 confidence class
# tensor([[7.50637e+02, 4.37279e+01, 1.15887e+03, 7.08682e+02, 8.18137e-01, 0.00000e+00],
# [9.33597e+01, 2.07387e+02, 1.04737e+03, 7.10224e+02, 5.78011e-01, 0.00000e+00],
# [4.24503e+02, 4.29092e+02, 5.16300e+02, 7.16425e+02, 5.68713e-01, 2.70000e+01]]) here's the error.
|
the error is because it's not encoded as a NumPy image here is the working code for anyone that may be interested. import torch
import d3dshot
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
d = d3dshot.create(capture_output="numpy")
img = d.screenshot()
# Image
# img = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg' # batched list of images
# Inference
results = model(img)
# Results
results.print()
results.show() # or .show()
# Data
print(results.pandas().xyxy[0]) # print img1 predictions (pixels)
# x1 y1 x2 y2 confidence class
# tensor([[7.50637e+02, 4.37279e+01, 1.15887e+03, 7.08682e+02, 8.18137e-01, 0.00000e+00],
# [9.33597e+01, 2.07387e+02, 1.04737e+03, 7.10224e+02, 5.78011e-01, 0.00000e+00],
# [4.24503e+02, 4.29092e+02, 5.16300e+02, 7.16425e+02, 5.68713e-01, 2.70000e+01]]) |
@coneill65 if a 3rd party package (especially one not in our requirements) is causing you issues in your custom code the place to inquire is directly with the package authors. |
❔Question
Hello, I was wondering if there is a way to inference on images in memory. For example, I wanted to serve the model as a web server but writing the file to the disk to inference and then deleting the file invokes significant overhead that could easily be avoided. If this is at all possible to do I would much appreciate some insight.
Thanks.
Additional context
The text was updated successfully, but these errors were encountered: