Q-bert commited on
Commit
9c2c5e4
1 Parent(s): 041db94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import sahi
3
  import torch
4
- from ultralyticsplus import YOLO, render_model_output
5
 
6
  # Download sample images
7
  sahi.utils.file.download_from_url(
@@ -60,26 +60,16 @@ def yolov8_inference(
60
  model.overrides["iou"] = iou_threshold
61
 
62
  # Perform model prediction
63
- results = model.predict(image, imgsz=image_size, return_outputs=True)
64
 
65
  # Initialize an empty list to store the output
66
  output = []
67
 
68
  # Iterate over the results
69
- for result in results:
70
- # Check if segmentation masks are available
71
- if 'masks' in result and result['masks'] is not None:
72
- masks = result['masks']['data']
73
- for i, (mask, box) in enumerate(zip(masks, result['boxes'])):
74
- label = model.names[int(result['boxes']['cls'][i])]
75
- mask_coords = mask.tolist() # Convert mask coordinates to list format
76
- output.append({"label": label, "mask_coords": mask_coords})
77
- else:
78
- # If masks are not available, just extract bounding box information
79
- for i, box in enumerate(result['boxes']):
80
- label = model.names[int(result['boxes']['cls'][i])]
81
- bbox = box['xyxy'].tolist() # Bounding box coordinates
82
- output.append({"label": label, "bbox_coords": bbox})
83
 
84
  return output
85
 
 
1
  import gradio as gr
2
  import sahi
3
  import torch
4
+ from ultralytics import YOLO
5
 
6
  # Download sample images
7
  sahi.utils.file.download_from_url(
 
60
  model.overrides["iou"] = iou_threshold
61
 
62
  # Perform model prediction
63
+ results = model(image)
64
 
65
  # Initialize an empty list to store the output
66
  output = []
67
 
68
  # Iterate over the results
69
+ for i,box in enumerate(results[0].boxes):
70
+ label = results[0].names[box.cls[0].item()]
71
+ bbox = box.xyxy[0]
72
+ output.append({"label": label, "bbox_coords": bbox})
 
 
 
 
 
 
 
 
 
 
73
 
74
  return output
75