Skip to main content

Run inference on Yolo Distribution Distillation model.

Project description

Yolo Ensemble Distribution Distillation

This repository contains code for running a model trained by distilling the distribution of an ensemble of Yolo teacher models into a single student models. This method improves the models performance and uncertainty estimation by leveraging the combined knowledge of multiple teacher models to distill a student model to predict a similar output distribution. The distilled model is fast with inference speed suitable for real-time apllications.

Example Usage

import torch
import cv2
import numpy as np
from yolo_ens_dist.utilz.utils import plot_boxes_cv2, plot_boxes_cv2_uncertainty, load_class_names
from yolo_ens_dist.utilz.torch_utils import do_detect
from yolo_ens_dist.model.models import Yolo_Ensemble_Distillation


conf_thresh = 0.4
nms_thresh = 0.4
height = 416
width = 416
num_classes = 10
imgfile = 'data/images/kitti/kitti_example_2.png'
weightsfile = 'weights/clean/bdd/dist/Yolo_bdd_teachers_only_1.pth'
class_names_path = 'data/bdd.names'
box_uncertainties = True


device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
class_names = load_class_names(class_names_path)
model = Yolo_Ensemble_Distillation(yolov3conv137weight=None, n_classes=num_classes, inference=True, temp=1, vis=True)

pretrained_dict = torch.load(weightsfile, map_location=device)
model.load_state_dict(pretrained_dict)
if device.type == 'cuda':
    model.cuda()

img = cv2.imread(imgfile)
sized = cv2.resize(img, (width, height))
sized = cv2.cvtColor(sized, cv2.COLOR_BGR2RGB)
boxes = do_detect(model, sized, conf_thresh, nms_thresh, uncertainties=True)

if box_uncertainties:
    output_image = plot_boxes_cv2_uncertainty(img, boxes[0][0], class_names=class_names)
else:
    output_image = plot_boxes_cv2(img, boxes[0][0], class_names=class_names)

cv2.imshow("frame", output_image)
cv2.waitKey(0)

alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Yolo_ED2_Demo-1.0.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

Yolo_ED2_Demo-1.0.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file Yolo_ED2_Demo-1.0.0.tar.gz.

File metadata

  • Download URL: Yolo_ED2_Demo-1.0.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.13

File hashes

Hashes for Yolo_ED2_Demo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 39bc5ec77a6970914233ea09ad4889e195d6d98c2a91e9d2731228816d2510c5
MD5 4d578c98c727cff2f54ad77aba8a248b
BLAKE2b-256 67d5094a59d93aae4b109b5b91fdd3822937bed3eb3b464d1e8c1df6f0debce9

See more details on using hashes here.

File details

Details for the file Yolo_ED2_Demo-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: Yolo_ED2_Demo-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.13

File hashes

Hashes for Yolo_ED2_Demo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bcea5936edc68a2f1585f7cc6410533ebe0163ef5ca4a5d05607b2e301c7f33
MD5 232caf9ddb9b6ef26c65737d3a660192
BLAKE2b-256 08cc15c8934aecf00b3b54a6a395cb4ea146bdb486314a3321218344146c73b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page