Girishug commited on
Commit
58d79c2
·
verified ·
1 Parent(s): 6ceca29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -68,8 +68,11 @@ def predict(image):
68
  for box, label in zip(boxes, labels):
69
  x1, y1, x2, y2 = box.astype(int)
70
  image_np = cv2.rectangle(image_np, (x1, y1), (x2, y2), (255, 0, 0), 2)
71
- class_name = COCO_CLASSES[label] # Get the class name
72
- image_np = cv2.putText(image_np, class_name, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
 
 
 
73
 
74
  # Ensure the output is in the correct format
75
  return Image.fromarray(image_np.astype(np.uint8))
 
68
  for box, label in zip(boxes, labels):
69
  x1, y1, x2, y2 = box.astype(int)
70
  image_np = cv2.rectangle(image_np, (x1, y1), (x2, y2), (255, 0, 0), 2)
71
+ if label < len(COCO_CLASSES): # Ensure label is within bounds
72
+ class_name = COCO_CLASSES[label] # Get the class name
73
+ image_np = cv2.putText(image_np, class_name, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
74
+ else:
75
+ print(f"Warning: Label {label} is out of bounds for COCO_CLASSES.")
76
 
77
  # Ensure the output is in the correct format
78
  return Image.fromarray(image_np.astype(np.uint8))