BhumikaMak commited on
Commit
d8f9e92
·
1 Parent(s): 4fe4bfa

Update: class lables

Browse files
Files changed (2) hide show
  1. yolov5.py +8 -5
  2. yolov8.py +8 -5
yolov5.py CHANGED
@@ -27,13 +27,16 @@ def parse_detections(results):
27
  return boxes, colors, names
28
 
29
 
30
- def draw_detections(boxes, colors, names, img):
31
- for box, color, name in zip(boxes, colors, names):
32
  xmin, ymin, xmax, ymax = box
 
33
  cv2.rectangle(img, (xmin, ymin), (xmax, ymax), color, 2)
34
- cv2.putText(img, name, (xmin, ymin - 5),
35
- cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2,
36
- lineType=cv2.LINE_AA)
 
 
37
  return img
38
 
39
 
 
27
  return boxes, colors, names
28
 
29
 
30
+ def draw_detections(boxes, colors, names, classes, img):
31
+ for box, color, name, cls in zip(boxes, colors, names, classes):
32
  xmin, ymin, xmax, ymax = box
33
+ label = f"{cls}: {name}" # Combine class ID and name
34
  cv2.rectangle(img, (xmin, ymin), (xmax, ymax), color, 2)
35
+ cv2.putText(
36
+ img, label, (xmin, ymin - 5),
37
+ cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2,
38
+ lineType=cv2.LINE_AA
39
+ )
40
  return img
41
 
42
 
yolov8.py CHANGED
@@ -24,13 +24,16 @@ def parse_detections(detections, model):
24
  names.append(name)
25
  return boxes, colors, names
26
 
27
- def draw_detections(boxes, colors, names, img):
28
- for box, color, name in zip(boxes, colors, names):
29
  xmin, ymin, xmax, ymax = box
 
30
  cv2.rectangle(img, (xmin, ymin), (xmax, ymax), color, 2)
31
- cv2.putText(img, name, (xmin, ymin - 5),
32
- cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2,
33
- lineType=cv2.LINE_AA)
 
 
34
  return img
35
 
36
  def generate_cam_image(model, target_layers, tensor, rgb_img, boxes):
 
24
  names.append(name)
25
  return boxes, colors, names
26
 
27
+ def draw_detections(boxes, colors, names, classes, img):
28
+ for box, color, name, cls in zip(boxes, colors, names, classes):
29
  xmin, ymin, xmax, ymax = box
30
+ label = f"{cls}: {name}" # Combine class ID and name
31
  cv2.rectangle(img, (xmin, ymin), (xmax, ymax), color, 2)
32
+ cv2.putText(
33
+ img, label, (xmin, ymin - 5),
34
+ cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2,
35
+ lineType=cv2.LINE_AA
36
+ )
37
  return img
38
 
39
  def generate_cam_image(model, target_layers, tensor, rgb_img, boxes):