nagasurendra commited on
Commit
156c9ac
·
verified ·
1 Parent(s): 257f31f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -14
app.py CHANGED
@@ -12,12 +12,6 @@ def safe_load_yolo_model(path):
12
  model_yolo11 = safe_load_yolo_model('./data/yolo11n.pt')
13
  model_best = safe_load_yolo_model('./data/best.pt')
14
 
15
- # Class names for YOLO model (replace with actual class names used in your YOLO model)
16
- yolo_classes = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe']
17
-
18
- # Class names for best.pt model (assumed classes for crack and pothole)
19
- best_classes = ['Crack', 'Pothole']
20
-
21
  def process_video(video):
22
  # Open the video using OpenCV
23
  cap = cv2.VideoCapture(video)
@@ -45,7 +39,8 @@ def process_video(video):
45
  for box in boxes:
46
  x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
47
  class_id = int(box.cls[0]) # Class index for YOLO
48
- label = f"YOLO: {yolo_classes[class_id]} - {box.conf[0]:.2f}" # Map class_id to class name
 
49
  cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
50
  cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
51
 
@@ -55,13 +50,8 @@ def process_video(video):
55
  for box in boxes:
56
  x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
57
  class_id = int(box.cls[0]) # Class index for best.pt
58
-
59
- # Check if the class_id is within the range of best_classes
60
- if class_id < len(best_classes):
61
- label = f"Best: {best_classes[class_id]} - {box.conf[0]:.2f}" # Map class_id to specific labels
62
- else:
63
- label = f"Best: Unknown Class - {box.conf[0]:.2f}" # Handle out of range class_id
64
-
65
  cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
66
  cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 0), 2)
67
 
 
12
  model_yolo11 = safe_load_yolo_model('./data/yolo11n.pt')
13
  model_best = safe_load_yolo_model('./data/best.pt')
14
 
 
 
 
 
 
 
15
  def process_video(video):
16
  # Open the video using OpenCV
17
  cap = cv2.VideoCapture(video)
 
39
  for box in boxes:
40
  x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
41
  class_id = int(box.cls[0]) # Class index for YOLO
42
+ # Use model's built-in class names
43
+ label = f"YOLO: {model_yolo11.names[class_id]} - {box.conf[0]:.2f}"
44
  cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
45
  cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
46
 
 
50
  for box in boxes:
51
  x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
52
  class_id = int(box.cls[0]) # Class index for best.pt
53
+ # Use model's built-in class names for best.pt
54
+ label = f"Best: {model_best.names[class_id]} - {box.conf[0]:.2f}"
 
 
 
 
 
55
  cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
56
  cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 0), 2)
57