AnandN commited on
Commit
d1b5d34
1 Parent(s): 3ee192f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -17,17 +17,14 @@ model = YOLO('best.pt')
17
  def show_preds_image(image_path):
18
  image = cv2.imread(image_path)
19
  outputs = model.predict(source=image_path)
20
- results = outputs[0].cpu().numpy()
21
- class_names = model.names
 
 
 
 
 
22
  for i, det in enumerate(results.boxes.xyxy):
23
- x_min, y_min, x_max, y_max = det
24
- # In this case, we don't have confidence and class index information,
25
- # but we can get the class name using the index from class_names
26
- class_index = i # Assuming class index corresponds to the loop index
27
- if class_index < len(class_names):
28
- class_name = class_names[class_index]
29
- else:
30
- class_name = "Unknown"
31
  cv2.rectangle(
32
  image,
33
  (int(det[0]), int(det[1])),
 
17
  def show_preds_image(image_path):
18
  image = cv2.imread(image_path)
19
  outputs = model.predict(source=image_path)
20
+ results = outputs[0].cpu().numpy()
21
+ class_name=""
22
+ for r in results:
23
+ # Get the class index
24
+ for c in r.boxes.cls:
25
+ class_name = model.names[int(c)]
26
+ print(class_name)
27
  for i, det in enumerate(results.boxes.xyxy):
 
 
 
 
 
 
 
 
28
  cv2.rectangle(
29
  image,
30
  (int(det[0]), int(det[1])),