Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from sahi.prediction import ObjectPrediction
|
4 |
from sahi.utils.cv import visualize_object_predictions, read_image
|
5 |
-
from ultralyticsplus import YOLO
|
6 |
|
7 |
|
8 |
def yolov8_inference(
|
@@ -23,39 +23,15 @@ def yolov8_inference(
|
|
23 |
Returns:
|
24 |
Rendered image
|
25 |
"""
|
26 |
-
model = YOLO(f'{model_path}.
|
27 |
# set model parameters
|
28 |
model.overrides['conf'] = conf_threshold # NMS confidence threshold
|
29 |
model.overrides['iou'] = iou_threshold # NMS IoU threshold
|
30 |
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
31 |
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
32 |
-
results = model.predict(image
|
33 |
-
|
34 |
-
|
35 |
-
if len(image_results)!=0:
|
36 |
-
image_predictions_in_xyxy_format = image_results['det']
|
37 |
-
for pred in image_predictions_in_xyxy_format:
|
38 |
-
x1, y1, x2, y2 = (
|
39 |
-
int(pred[0]),
|
40 |
-
int(pred[1]),
|
41 |
-
int(pred[2]),
|
42 |
-
int(pred[3]),
|
43 |
-
)
|
44 |
-
bbox = [x1, y1, x2, y2]
|
45 |
-
score = pred[4]
|
46 |
-
category_name = model.model.names[int(pred[5])]
|
47 |
-
category_id = pred[5]
|
48 |
-
object_prediction = ObjectPrediction(
|
49 |
-
bbox=bbox,
|
50 |
-
category_id=int(category_id),
|
51 |
-
score=score,
|
52 |
-
category_name=category_name,
|
53 |
-
)
|
54 |
-
object_prediction_list.append(object_prediction)
|
55 |
-
|
56 |
-
image = read_image(image)
|
57 |
-
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
58 |
-
return output_image['image']
|
59 |
|
60 |
|
61 |
inputs = [
|
|
|
2 |
import torch
|
3 |
from sahi.prediction import ObjectPrediction
|
4 |
from sahi.utils.cv import visualize_object_predictions, read_image
|
5 |
+
from ultralyticsplus import YOLO, render_result
|
6 |
|
7 |
|
8 |
def yolov8_inference(
|
|
|
23 |
Returns:
|
24 |
Rendered image
|
25 |
"""
|
26 |
+
model = YOLO(f'kadirnar/{model_path}-v8.0')
|
27 |
# set model parameters
|
28 |
model.overrides['conf'] = conf_threshold # NMS confidence threshold
|
29 |
model.overrides['iou'] = iou_threshold # NMS IoU threshold
|
30 |
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
31 |
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
32 |
+
results = model.predict(image)
|
33 |
+
render = render_result(model=model, image=image, result=results[0])
|
34 |
+
return render
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
inputs = [
|