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

Filter results from predictions #6213

Closed
1 task done
maurokenny opened this issue Jan 5, 2022 · 5 comments
Closed
1 task done

Filter results from predictions #6213

maurokenny opened this issue Jan 5, 2022 · 5 comments
Labels
question Further information is requested Stale

Comments

@maurokenny
Copy link

Search before asking

Question

From the code:

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)

# Images
imgs = ['https://ultralytics.com/images/zidane.jpg']  # batch of images

# Inference
results = model(imgs)

# Results
results.print()
results.save()  # or .show()

results.xyxy[0]  # img1 predictions (tensor)
results.pandas().xyxy[0]  # img1 predictions (pandas)

if I run results.render() it will show all detected boxes.

How can I modify the results variable to filter just some classes (e.g.: classes 0 and 1) and then run results.render() to show just the filtered classes? Without doing results = model(imgs) again.

Thanks

Additional

No response

@maurokenny maurokenny added the question Further information is requested label Jan 5, 2022
@glenn-jocher
Copy link
Member

glenn-jocher commented Jan 5, 2022

@maurokenny see PyTorch Hub tutorial for class filtering:

Inference Settings

YOLOv5 models contain various inference attributes such as confidence threshold, IoU threshold, etc. which can be set by:

model.conf = 0.25  # NMS confidence threshold
      iou = 0.45  # NMS IoU threshold
      agnostic = False  # NMS class-agnostic
      multi_label = False  # NMS multiple labels per box
      classes = None  # (optional list) filter by class, i.e. = [0, 15, 16] for COCO persons, cats and dogs
      max_det = 1000  # maximum number of detections per image
      amp = False  # Automatic Mixed Precision (AMP) inference

results = model(imgs, size=320)  # custom inference size

YOLOv5 Tutorials

Good luck 🍀 and let us know if you have any other questions!

@maurokenny
Copy link
Author

In this case I have to change the results before. In my case I already have the results variable

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2022

👋 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 ⭐!

@github-actions github-actions bot added the Stale label Feb 6, 2022
@agupt013
Copy link

Hi @maurokenny , were you able to figure out how to filter predictions? I'm trying to save false positives and false negatives.

Thanks!

@github-actions github-actions bot removed the Stale label Feb 12, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2022

👋 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 ⭐!

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

No branches or pull requests

3 participants