Skip to content
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

Adding tracker after detection #1331

Closed
berkantay opened this issue Nov 10, 2020 · 5 comments
Closed

Adding tracker after detection #1331

berkantay opened this issue Nov 10, 2020 · 5 comments
Labels
question Further information is requested

Comments

@berkantay
Copy link

berkantay commented Nov 10, 2020

❔Question

First of all thanks for this repository, it is completely useful. I have reached the accuracy and the performance of detection for my specific case. Now my aim is to embed some tracking algorithm just after detection. How can I get the bounding box coordinates. I am planning to pass those coordinates to the tracker when detection is occured.

@berkantay berkantay added the question Further information is requested label Nov 10, 2020
@glenn-jocher
Copy link
Member

glenn-jocher commented Nov 10, 2020

See https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading

import torch
from PIL import Image

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True).fuse().eval()  # yolov5s.pt
model = model.autoshape()  # for autoshaping of PIL/cv2/np inputs and NMS

# Images
img = Image.open('data/images/zidane.jpg')  # PIL image

# Inference
prediction = model(img)

@shashi7679
Copy link

shashi7679 commented Jun 26, 2022

@glenn-jocher Hi... I am trying to do inference in my own way, using the torchscript file trained on my custom dataset.
When I am using the method for inference, I am getting prediction as a tuple consisting of a tensor of size (1 X 25200 X 85).

Now how to get xmin, xmax, ymin, ymax from this point.

I have been following this (https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading#issuecomment-695146444) approach for inference.

Please help me out.

Thanks in advance.

@glenn-jocher
Copy link
Member

@shashi7679 sorry for the confusion. PyTorch Hub YOLOv5 models treat torch inputs as pass-throughs, so no pre or post processing is performed on torch inputs.

If you want a results object then please pass numpy arrays, PIL, cv2, file paths, etc.

@shashi7679
Copy link

@glenn-jocher But when I am passing array/PIL/cv2.. I am getting this error.

RuntimeError: forward() Expected a value of type 'Tensor' for argument 'x' but instead found type 'JpegImageFile'.
Position: 1
Value: <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1796x2717 at 0x21D086F19A0>
Declaration: forward(torch.models.yolo.Model self, Tensor x) -> ((Tensor))
Cast error details: Unable to cast Python instance to C++ type (compile in debug mode for details)

@glenn-jocher
Copy link
Member

glenn-jocher commented Jun 26, 2022

@shashi7679 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. 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:

  • Minimal – Use as little code as possible to produce the problem
  • Complete – Provide all parts someone else needs to reproduce the problem
  • Reproducible – Test the code you're about to provide to make sure it reproduces the problem

For Ultralytics to provide assistance your code should also be:

  • Current – Verify that your code is up-to-date with GitHub master, and if necessary git pull or git clone a new copy to ensure your problem has not already been solved in master.
  • Unmodified – Your problem must be reproducible using official YOLOv5 code without changes. Ultralytics does not provide support for custom code ⚠️.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants