Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
import torch
|
3 |
-
from ultralyticsplus import
|
|
|
|
|
4 |
|
5 |
|
6 |
-
def
|
7 |
image_size: int = 640,
|
8 |
conf_threshold: float = 0.4,
|
9 |
-
iou_threshold: float = 0.
|
10 |
-
"""This function performs
|
11 |
-
|
12 |
Args:
|
13 |
-
image (gr.
|
14 |
-
image_size (
|
15 |
-
conf_threshold (
|
16 |
-
iou_threshold (
|
17 |
"""
|
18 |
# Load the YOLOv8 model from the 'best.pt' checkpoint
|
19 |
-
model_path = "
|
20 |
-
model =
|
21 |
|
22 |
# Perform object detection on the input image using the YOLOv8 model
|
23 |
results = model.predict(image,
|
@@ -32,35 +36,33 @@ def yoloV9_func(image: gr.Image = None,
|
|
32 |
print("Probability:", box.conf)
|
33 |
|
34 |
# Render the output image with bounding boxes around detected objects
|
35 |
-
render =
|
36 |
return render
|
37 |
|
38 |
|
39 |
inputs = [
|
40 |
gr.Image(type="filepath", label="Input Image"),
|
41 |
-
gr.Slider(minimum=320, maximum=1280, step=32, label="Image Size"),
|
42 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="Confidence Threshold"),
|
43 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="IOU Threshold"),
|
44 |
]
|
45 |
|
46 |
-
|
47 |
outputs = gr.Image(type="filepath", label="Output Image")
|
48 |
|
49 |
-
title = "
|
50 |
-
|
51 |
|
52 |
examples = [['one.jpg', 640, 0.5, 0.7],
|
53 |
['two.jpg', 640, 0.5, 0.6],
|
54 |
['three.jpg', 640, 0.5, 0.8]]
|
55 |
|
56 |
yolo_app = gr.Interface(
|
57 |
-
fn=
|
58 |
inputs=inputs,
|
59 |
outputs=outputs,
|
60 |
title=title,
|
61 |
examples=examples,
|
62 |
-
cache_examples=
|
63 |
)
|
64 |
|
65 |
# Launch the Gradio interface in debug mode with queue enabled
|
66 |
-
yolo_app.launch(debug=True,
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
+
from ultralytics import YOLO
|
4 |
+
model = YOLO('./best_model.pt') # load your custom trained model
|
5 |
import torch
|
6 |
+
#from ultralyticsplus import render_result
|
7 |
+
from render import custom_render_result
|
8 |
+
|
9 |
|
10 |
|
11 |
+
def yoloV8_func(image: gr.Image = None,
|
12 |
image_size: int = 640,
|
13 |
conf_threshold: float = 0.4,
|
14 |
+
iou_threshold: float = 0.5):
|
15 |
+
"""This function performs YOLOv8 object detection on the given image.
|
|
|
16 |
Args:
|
17 |
+
image (gr.Image, optional): Input image to detect objects on. Defaults to None.
|
18 |
+
image_size (int, optional): Desired image size for the model. Defaults to 640.
|
19 |
+
conf_threshold (float, optional): Confidence threshold for object detection. Defaults to 0.4.
|
20 |
+
iou_threshold (float, optional): Intersection over Union threshold for object detection. Defaults to 0.50.
|
21 |
"""
|
22 |
# Load the YOLOv8 model from the 'best.pt' checkpoint
|
23 |
+
model_path = "yolov5s.pt"
|
24 |
+
# model = torch.hub.load('ultralytics/yolov8', 'custom', path='/content/best.pt', force_reload=True, trust_repo=True)
|
25 |
|
26 |
# Perform object detection on the input image using the YOLOv8 model
|
27 |
results = model.predict(image,
|
|
|
36 |
print("Probability:", box.conf)
|
37 |
|
38 |
# Render the output image with bounding boxes around detected objects
|
39 |
+
render = custom_render_result(model=model, image=image, result=results[0])
|
40 |
return render
|
41 |
|
42 |
|
43 |
inputs = [
|
44 |
gr.Image(type="filepath", label="Input Image"),
|
45 |
+
gr.Slider(minimum=320, maximum=1280, step=32, label="Image Size", value=640),
|
46 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="Confidence Threshold"),
|
47 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label="IOU Threshold"),
|
48 |
]
|
49 |
|
|
|
50 |
outputs = gr.Image(type="filepath", label="Output Image")
|
51 |
|
52 |
+
title = "YOLOv8 101: Custom Object Detection on meter"
|
|
|
53 |
|
54 |
examples = [['one.jpg', 640, 0.5, 0.7],
|
55 |
['two.jpg', 640, 0.5, 0.6],
|
56 |
['three.jpg', 640, 0.5, 0.8]]
|
57 |
|
58 |
yolo_app = gr.Interface(
|
59 |
+
fn=yoloV8_func,
|
60 |
inputs=inputs,
|
61 |
outputs=outputs,
|
62 |
title=title,
|
63 |
examples=examples,
|
64 |
+
cache_examples=False,
|
65 |
)
|
66 |
|
67 |
# Launch the Gradio interface in debug mode with queue enabled
|
68 |
+
yolo_app.launch(debug=True,share=True).queue()
|