Delete app.py
Browse files
app.py
DELETED
@@ -1,71 +0,0 @@
|
|
1 |
-
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 |
-
|
9 |
-
def yolov8_go(
|
10 |
-
image: gr.inputs.Image = None,
|
11 |
-
model_path: gr.inputs.Dropdown = None,
|
12 |
-
image_size: gr.inputs.Slider = 640,
|
13 |
-
conf_threshold: gr.inputs.Slider = 0.25,
|
14 |
-
iou_threshold: gr.inputs.Slider = 0.45,
|
15 |
-
):
|
16 |
-
|
17 |
-
model = YOLO(model_path)
|
18 |
-
model.conf = conf_threshold
|
19 |
-
model.iou = iou_threshold
|
20 |
-
results = model.predict(image, imgsz=image_size, return_outputs=True)
|
21 |
-
object_prediction_list = []
|
22 |
-
for _, image_results in enumerate(results):
|
23 |
-
if len(image_results)!=0:
|
24 |
-
image_predictions_in_xyxy_format = image_results['det']
|
25 |
-
for pred in image_predictions_in_xyxy_format:
|
26 |
-
x1, y1, x2, y2 = (
|
27 |
-
int(pred[0]),
|
28 |
-
int(pred[1]),
|
29 |
-
int(pred[2]),
|
30 |
-
int(pred[3]),
|
31 |
-
)
|
32 |
-
bbox = [x1, y1, x2, y2]
|
33 |
-
score = pred[4]
|
34 |
-
category_name = model.model.names[int(pred[5])]
|
35 |
-
category_id = pred[5]
|
36 |
-
object_prediction = ObjectPrediction(
|
37 |
-
bbox=bbox,
|
38 |
-
category_id=int(category_id),
|
39 |
-
score=score,
|
40 |
-
category_name=category_name,
|
41 |
-
)
|
42 |
-
object_prediction_list.append(object_prediction)
|
43 |
-
|
44 |
-
image = read_image(image)
|
45 |
-
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
46 |
-
return output_image['image']
|
47 |
-
|
48 |
-
|
49 |
-
inputs = [
|
50 |
-
gr.inputs.Image(type="filepath", label="Input Image"),
|
51 |
-
gr.inputs.Dropdown(["aijack/yv8/yv8n.pt", "aijack/yv8/yv8m.pt","aijack/yv8/yv8x.pt"],
|
52 |
-
default="aijack/yv8/blob/main/yv8m.pt", label="Model"),
|
53 |
-
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
54 |
-
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
55 |
-
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
|
56 |
-
]
|
57 |
-
|
58 |
-
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
59 |
-
title = "Ultralytics YOLOv8: State-of-the-Art YOLO Models"
|
60 |
-
|
61 |
-
examples = [['test1.jpg', 'aijack/yv8/blob/main/yv8m.pt', 640, 0.25, 0.45], ['test2.jpeg', 'aijack/yv8/yv8x.pt', 1280, 0.25, 0.45]]
|
62 |
-
demo_app = gr.Interface(
|
63 |
-
fn=yolov8_go,
|
64 |
-
inputs=inputs,
|
65 |
-
outputs=outputs,
|
66 |
-
title=title,
|
67 |
-
examples=examples,
|
68 |
-
cache_examples=True,
|
69 |
-
theme='huggingface',
|
70 |
-
)
|
71 |
-
demo_app.launch(debug=True, enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|