yolov5 icon indicating copy to clipboard operation
yolov5 copied to clipboard

Model Ensembling With PyTorch Hub

Open ertugrul-dmr opened this issue 2 years ago • 4 comments

Search before asking

  • [X] I have searched the YOLOv5 issues and discussions and found no similar questions.

Question

I know it's possible to ensemble multiple models with detect.py, but is it possible to do ensemble or do TTA with PyTorch Hub interface?

Let's say:

import torch

# Model
model_a = torch.hub.load('path/to/yolov5', 'custom', path='path/to/model_1.pt', source='local')
model_b = torch.hub.load('path/to/yolov5', 'custom', path='path/to/model_2.pt', source='local')

# Image
im = 'https://ultralytics.com/images/zidane.jpg'

# Inference
results = ???

results.pandas().xyxy[0]

How could I get results in a standardized way with this setting?

Additional

No response

ertugrul-dmr avatar Jul 18 '22 14:07 ertugrul-dmr

@ertugrul-dmr YOLOv5 PyTorch Hub models can use TTA with the augment argument:

results = model(im, augment=True)

You could customize some sort of Ensemble() using the Ensemble() module on your own, i.e. Ensemble two models and then wrap them in AutoShape: https://github.com/ultralytics/yolov5/blob/92e47b85d952274480c8c5efa5900e686241a96b/models/experimental.py#L61-L72

glenn-jocher avatar Jul 19 '22 17:07 glenn-jocher

@ertugrul-dmr Hi, did you find a way to ensemble with torch.hub?

kaamlaS avatar Aug 10 '22 08:08 kaamlaS

@kaamlaS yeah, wasn't an optimal solution but I kept results for every single image and then applied Weighted boxes fusion over them.

Ref: Weighted boxes fusion

ertugrul-dmr avatar Aug 10 '22 09:08 ertugrul-dmr

okay, cool. im going to give this a look. thank you!

kaamlaS avatar Aug 10 '22 10:08 kaamlaS

did you find any location for ensembling using torch.hub.load?

Sarveshsh8 avatar Aug 16 '22 05:08 Sarveshsh8

👋 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:

  • Wiki – https://github.com/ultralytics/yolov5/wiki
  • Tutorials – https://docs.ultralytics.com/yolov5
  • Docs – https://docs.ultralytics.com

Access additional Ultralytics ⚡ resources:

  • Ultralytics HUB – https://ultralytics.com/hub
  • Vision API – https://ultralytics.com/yolov5
  • About Us – https://ultralytics.com/about
  • Join Our Team – https://ultralytics.com/work
  • Contact Us – https://ultralytics.com/contact

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[bot] avatar Sep 16 '22 00:09 github-actions[bot]

@Sarveshsh8 Weighted boxes fusion seems like a solid approach for ensembling. Thanks for sharing! Let me know if there's anything else I can help with.

glenn-jocher avatar Nov 15 '23 14:11 glenn-jocher