Views
No views yet
pip install git+https://github.com/nielsrogge/yolov10.git@feature/add_hf supervision1from ultralytics import YOLOv10
2import supervision as sv
3from PIL import Image
4import requests
5
6# load model
7model = YOLOv10.from_pretrained("nielsr/yolov10n")
8
9# load image
10url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
11image = Image.open(requests.get(url, stream=True).raw)
12image = np.array(image)
13
14# perform inference
15results = model(source=image, conf=0.25, verbose=False)[0]
16detections = sv.Detections.from_ultralytics(results)
17box_annotator = sv.BoxAnnotator()
18
19category_dict = {
20 0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
21 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant',
22 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat',
23 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
24 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag',
25 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard',
26 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove',
27 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
28 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl',
29 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli',
30 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake',
31 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
32 61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard',
33 67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink',
34 72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors',
35 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
36}
37
38labels = [
39 f"{category_dict[class_id]} {confidence:.2f}"
40 for class_id, confidence in zip(detections.class_id, detections.confidence)
41]
42annotated_image = box_annotator.annotate(
43 image.copy(), detections=detections, labels=labels
44)
45
46Image.fromarray(annotated_image)
@misc{wang2024yolov10,
title={YOLOv10: Real-Time End-to-End Object Detection},
author={Ao Wang and Hui Chen and Lihao Liu and Kai Chen and Zijia Lin and Jungong Han and Guiguang Ding},
year={2024},
eprint={2405.14458},
archivePrefix={arXiv},
primaryClass={cs.CV}
}