Views
No views yet
git clone https://github.com/WongKinYiu/yolov9.git
cd yolov9hf_hub_download and use the loading function in helpers of YOLOv9.1from huggingface_hub import hf_hub_download
2hf_hub_download("merve/yolov9", filename="yolov9-c.pt", local_dir="./")1# make sure you have the following dependencies
2import torch
3import numpy as np
4from models.common import DetectMultiBackend
5from utils.general import non_max_suppression, scale_boxes
6from utils.torch_utils import select_device, smart_inference_mode
7from utils.augmentations import letterbox
8import PIL.Image
9
10@smart_inference_mode()
11def predict(image_path, weights='yolov9-c.pt', imgsz=640, conf_thres=0.1, iou_thres=0.45):
12 # Initialize
13 device = select_device('0')
14 model = DetectMultiBackend(weights='yolov9-c.pt', device="0", fp16=False, data='data/coco.yaml')
15 stride, names, pt = model.stride, model.names, model.pt
16
17 # Load image
18 image = np.array(PIL.Image.open(image_path))
19 img = letterbox(img0, imgsz, stride=stride, auto=True)[0]
20 img = img[:, :, ::-1].transpose(2, 0, 1)
21 img = np.ascontiguousarray(img)
22 img = torch.from_numpy(img).to(device).float()
23 img /= 255.0
24 if img.ndimension() == 3:
25 img = img.unsqueeze(0)
26
27 # Inference
28 pred = model(img, augment=False, visualize=False)
29
30 # Apply NMS
31 pred = non_max_suppression(pred[0][0], conf_thres, iou_thres, classes=None, max_det=1000)@article{wang2024yolov9,
title={{YOLOv9}: Learning What You Want to Learn Using Programmable Gradient Information},
author={Wang, Chien-Yao and Liao, Hong-Yuan Mark},
booktitle={arXiv preprint arXiv:2402.13616},
year={2024}
}