Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,6 @@ import torch
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
import gradio as gr
|
| 5 |
-
from sahi.prediction import ObjectPrediction
|
| 6 |
-
from sahi.utils.cv import visualize_object_predictions, read_image
|
| 7 |
|
| 8 |
|
| 9 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
|
|
@@ -19,41 +17,13 @@ model.max_det = 1000
|
|
| 19 |
def detect(img):
|
| 20 |
|
| 21 |
|
| 22 |
-
results = model
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
for pred in image_predictions_in_xyxy_format:
|
| 30 |
-
x1, y1, x2, y2 = (
|
| 31 |
-
int(pred[0]),
|
| 32 |
-
int(pred[1]),
|
| 33 |
-
int(pred[2]),
|
| 34 |
-
int(pred[3]),
|
| 35 |
-
)
|
| 36 |
-
bbox = [x1, y1, x2, y2]
|
| 37 |
-
score = pred[4]
|
| 38 |
-
category_name = model.model.names[int(pred[5])]
|
| 39 |
-
category_id = pred[5]
|
| 40 |
-
object_prediction = ObjectPrediction(
|
| 41 |
-
bbox=bbox,
|
| 42 |
-
category_id=int(category_id),
|
| 43 |
-
score=score,
|
| 44 |
-
category_name=category_name,
|
| 45 |
-
)
|
| 46 |
-
object_prediction_list.append(object_prediction)
|
| 47 |
-
|
| 48 |
-
image = read_image(image)
|
| 49 |
-
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
| 50 |
-
return output_image['image']
|
| 51 |
-
|
| 52 |
-
def drawRectangles(image, dfResults):
|
| 53 |
-
for index, row in dfResults.iterrows():
|
| 54 |
-
print( (row['xmin'], row['ymin']))
|
| 55 |
-
image = cv2.rectangle(image, (row['xmin'], row['ymin']), (row['xmax'], row['ymax']), (255, 0, 0), 2)
|
| 56 |
-
return image
|
| 57 |
|
| 58 |
|
| 59 |
img = gr.inputs.Image(shape=(192, 192))
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
|
|
|
|
| 17 |
def detect(img):
|
| 18 |
|
| 19 |
|
| 20 |
+
results = model(img, size=640)
|
| 21 |
+
|
| 22 |
+
predictions = results.pred[0]
|
| 23 |
+
boxes = predictions[:, :4] # x1, y1, x2, y2
|
| 24 |
+
scores = predictions[:, 4]
|
| 25 |
+
categories = predictions[:, 5]
|
| 26 |
+
return img.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
img = gr.inputs.Image(shape=(192, 192))
|