Spaces:
Running
Running
Commit
·
44688fd
1
Parent(s):
6e67afa
Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,10 @@ import supervision as sv
|
|
2 |
import gradio as gr
|
3 |
from ultralytics import YOLO
|
4 |
import sahi
|
5 |
-
|
6 |
|
7 |
|
8 |
# Images
|
9 |
-
sahi.utils.file.download_from_url(
|
10 |
-
"https://transform.roboflow.com/zD7y6XOoQnh7WC160Ae7/4d51f997137c0dca78fa2c9154e0b51a/thumb.jpg",
|
11 |
-
"f1.jpg",
|
12 |
-
)
|
13 |
sahi.utils.file.download_from_url(
|
14 |
"https://transform.roboflow.com/zD7y6XOoQnh7WC160Ae7/48174c7c26c2cbca52b084ebbb03d215/thumb.jpg",
|
15 |
"f2.jpg",
|
@@ -28,19 +24,17 @@ annotatormask=sv.MaskAnnotator()
|
|
28 |
|
29 |
def yolov8_inference(
|
30 |
image: gr.inputs.Image = None,
|
31 |
-
|
32 |
-
image_size: gr.inputs.Slider = 360,
|
33 |
-
conf_threshold: gr.inputs.Slider = 0.25,
|
34 |
iou_threshold: gr.inputs.Slider = 0.45,
|
35 |
):
|
36 |
|
37 |
-
|
38 |
-
model = YOLO("
|
39 |
-
|
40 |
-
|
41 |
detections = sv.Detections.from_yolov8(results)
|
42 |
-
annotated_image =
|
43 |
-
annotated_image =
|
44 |
|
45 |
|
46 |
|
@@ -61,7 +55,6 @@ outputs = gr.Image(type="filepath", label="Output Image")
|
|
61 |
title = "Ultralytics YOLOv8 Segmentation Demo"
|
62 |
import os
|
63 |
examples = [
|
64 |
-
["f1.jpg", 0.6, 0.45],
|
65 |
["f2.jpg", 0.25, 0.45],
|
66 |
["f3.jpg", 0.25, 0.45],
|
67 |
]
|
@@ -73,4 +66,4 @@ demo_app = gr.Interface(examples=examples,
|
|
73 |
cache_examples=True,
|
74 |
theme="default",
|
75 |
)
|
76 |
-
demo_app.launch(debug=
|
|
|
2 |
import gradio as gr
|
3 |
from ultralytics import YOLO
|
4 |
import sahi
|
5 |
+
import numpy as np
|
6 |
|
7 |
|
8 |
# Images
|
|
|
|
|
|
|
|
|
9 |
sahi.utils.file.download_from_url(
|
10 |
"https://transform.roboflow.com/zD7y6XOoQnh7WC160Ae7/48174c7c26c2cbca52b084ebbb03d215/thumb.jpg",
|
11 |
"f2.jpg",
|
|
|
24 |
|
25 |
def yolov8_inference(
|
26 |
image: gr.inputs.Image = None,
|
27 |
+
conf_threshold: gr.inputs.Slider = 0.5,
|
|
|
|
|
28 |
iou_threshold: gr.inputs.Slider = 0.45,
|
29 |
):
|
30 |
|
31 |
+
image=image[:, :, ::-1].astype(np.uint8)
|
32 |
+
model = YOLO("/content/segment/train/weights/best.pt")
|
33 |
+
results = model(image,imgsz=320)[0]
|
34 |
+
image=image[:, :, ::-1].astype(np.uint8)
|
35 |
detections = sv.Detections.from_yolov8(results)
|
36 |
+
annotated_image = annotatormask.annotate(scene=image, detections=detections)
|
37 |
+
annotated_image = annotatorbbox.annotate(scene=annotated_image , detections=detections)
|
38 |
|
39 |
|
40 |
|
|
|
55 |
title = "Ultralytics YOLOv8 Segmentation Demo"
|
56 |
import os
|
57 |
examples = [
|
|
|
58 |
["f2.jpg", 0.25, 0.45],
|
59 |
["f3.jpg", 0.25, 0.45],
|
60 |
]
|
|
|
66 |
cache_examples=True,
|
67 |
theme="default",
|
68 |
)
|
69 |
+
demo_app.launch(debug=False, enable_queue=True)
|