kadirnar commited on
Commit
b5c7bac
1 Parent(s): 3db8d6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -12,6 +12,25 @@ def download_models(model_id):
12
  MODEL_PATH = 'yolov10n.pt'
13
  model = YOLOv10(MODEL_PATH)
14
  box_annotator = sv.BoxAnnotator()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  @spaces.GPU(duration=200)
17
  def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold):
@@ -20,7 +39,7 @@ def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold
20
  detections = sv.Detections.from_ultralytics(results)
21
 
22
  labels = [
23
- f"{model.model.names[class_id]} {confidence:.2f}"
24
  for class_id, confidence in zip(detections.class_id, detections.confidence)
25
  ]
26
  annotated_image = box_annotator.annotate(image, detections=detections, labels=labels)
 
12
  MODEL_PATH = 'yolov10n.pt'
13
  model = YOLOv10(MODEL_PATH)
14
  box_annotator = sv.BoxAnnotator()
15
+ category_dict = {
16
+ 0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
17
+ 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant',
18
+ 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat',
19
+ 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
20
+ 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag',
21
+ 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard',
22
+ 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove',
23
+ 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
24
+ 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl',
25
+ 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli',
26
+ 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake',
27
+ 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
28
+ 61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard',
29
+ 67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink',
30
+ 72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors',
31
+ 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
32
+ }
33
+
34
 
35
  @spaces.GPU(duration=200)
36
  def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold):
 
39
  detections = sv.Detections.from_ultralytics(results)
40
 
41
  labels = [
42
+ f"{category_dict[class_id]} {confidence:.2f}"
43
  for class_id, confidence in zip(detections.class_id, detections.confidence)
44
  ]
45
  annotated_image = box_annotator.annotate(image, detections=detections, labels=labels)