Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
|
|
|
|
|
|
|
|
3 |
#import requests
|
4 |
import os
|
5 |
-
|
6 |
-
from ultralyticsplus import YOLO, render_result
|
7 |
|
8 |
image_path = [['test_images/2a998cfb0901db5f8210.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45],['test_images/2ce19ce0191acb44920b.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45],
|
9 |
['test_images/2daab6ea3310e14eb801.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45], ['test_images/4a137deefb14294a7005 (1).jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45],
|
@@ -27,15 +30,37 @@ def yolov8_img_inference(
|
|
27 |
iou_threshold: gr.inputs.Slider = 0.45,
|
28 |
):
|
29 |
model = YOLO(model_path)
|
30 |
-
model.
|
31 |
-
model.
|
32 |
-
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
33 |
-
model.overrides['max_det'] = 1000
|
34 |
# image = read_image(image)
|
35 |
-
results = model.predict(image)
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
inputs_image = [
|
41 |
gr.inputs.Image(type="filepath", label="Input Image"),
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from sahi.prediction import ObjectPrediction
|
6 |
+
from sahi.utils.cv import visualize_object_predictions, read_image
|
7 |
#import requests
|
8 |
import os
|
9 |
+
from ultralyticsplus import YOLO
|
|
|
10 |
|
11 |
image_path = [['test_images/2a998cfb0901db5f8210.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45],['test_images/2ce19ce0191acb44920b.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45],
|
12 |
['test_images/2daab6ea3310e14eb801.jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45], ['test_images/4a137deefb14294a7005 (1).jpg','linhcuem/chamdiem_yolov8_ver10', 640, 0.25, 0.45],
|
|
|
30 |
iou_threshold: gr.inputs.Slider = 0.45,
|
31 |
):
|
32 |
model = YOLO(model_path)
|
33 |
+
model.conf = conf_threshold
|
34 |
+
model.iou= iou_threshold
|
35 |
+
# model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
36 |
+
# model.overrides['max_det'] = 1000
|
37 |
# image = read_image(image)
|
38 |
+
results = model.predict(image, imgz=image_size, return_outputs=True)
|
39 |
+
object_prediction_list = []
|
40 |
+
for _, image_results in enumerate(results):
|
41 |
+
if len(image_results)!=0:
|
42 |
+
image_prediction_in_xyxy_format = image_results['det']
|
43 |
+
for pred in image_prediction_in_xyxy_format:
|
44 |
+
x1, y1, x2, y2 = (
|
45 |
+
int(pred[0]),
|
46 |
+
int(pred[1]),
|
47 |
+
int(pred[2]),
|
48 |
+
int(pred[3]),
|
49 |
+
)
|
50 |
+
bbox = [x1, y1, x2, y2]
|
51 |
+
score = pred[4]
|
52 |
+
category_name = model.model.names[int(pred[5])]
|
53 |
+
category_id = pred[5]
|
54 |
+
object_prediction = ObjectPrediction(
|
55 |
+
bbox=bbox,
|
56 |
+
category_id=int(category_id),
|
57 |
+
score=score,
|
58 |
+
category_name=category_name,
|
59 |
+
)
|
60 |
+
object_prediction_list.append(object_prediction)
|
61 |
+
image = read_image(image)
|
62 |
+
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
63 |
+
return output_image['image']
|
64 |
|
65 |
inputs_image = [
|
66 |
gr.inputs.Image(type="filepath", label="Input Image"),
|