sunidhi7 commited on
Commit
ece8b2c
·
verified ·
1 Parent(s): 2f87e2c

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -101
app.py DELETED
@@ -1,101 +0,0 @@
1
-
2
- import gradio as gr
3
- import sahi
4
- import torch
5
- from ultralyticsplus import YOLO, render_model_output
6
-
7
- # Images
8
- sahi.utils.file.download_from_url(
9
- "https://raw.githubusercontent.com/kadirnar/dethub/main/data/images/highway.jpg",
10
- "highway.jpg",
11
- )
12
- sahi.utils.file.download_from_url(
13
- "https://raw.githubusercontent.com/obss/sahi/main/tests/data/small-vehicles1.jpeg",
14
- "small-vehicles1.jpeg",
15
- )
16
- sahi.utils.file.download_from_url(
17
- "https://raw.githubusercontent.com/ultralytics/yolov5/master/data/images/zidane.jpg",
18
- "zidane.jpg",
19
- )
20
-
21
-
22
- model_names = [
23
- "yolov8n-seg.pt",
24
- "yolov8s-seg.pt",
25
- "yolov8m-seg.pt",
26
- "yolov8l-seg.pt",
27
- "yolov8x-seg.pt",
28
- ]
29
-
30
- current_model_name = "yolov8m-seg.pt"
31
- model = YOLO(current_model_name)
32
-
33
-
34
- def yolov8_inference(
35
- image: gr.inputs.Image = None,
36
- model_name: gr.inputs.Dropdown = None,
37
- image_size: gr.inputs.Slider = 640,
38
- conf_threshold: gr.inputs.Slider = 0.25,
39
- iou_threshold: gr.inputs.Slider = 0.45,
40
- ):
41
- """
42
- YOLOv8 inference function
43
- Args:
44
- image: Input image
45
- model_name: Name of the model
46
- image_size: Image size
47
- conf_threshold: Confidence threshold
48
- iou_threshold: IOU threshold
49
- Returns:
50
- Rendered image
51
- """
52
- global model
53
- global current_model_name
54
- if model_name != current_model_name:
55
- model = YOLO(model_name)
56
- current_model_name = model_name
57
- model.overrides["conf"] = conf_threshold
58
- model.overrides["iou"] = iou_threshold
59
- results = model.predict(image, imgsz=image_size, return_outputs=True)
60
- renders = []
61
- for image_results in model.predict(image, imgsz=image_size, return_outputs=True):
62
- render = render_model_output(
63
- model=model, image=image, model_output=image_results
64
- )
65
- renders.append(render)
66
-
67
- return renders[0]
68
-
69
-
70
- inputs = [
71
- gr.Image(type="filepath", label="Input Image"),
72
- gr.Dropdown(
73
- model_names,
74
- value=current_model_name,
75
- label="Model type",
76
- ),
77
- gr.Slider(minimum=320, maximum=1280, value=640, step=32, label="Image Size"),
78
- gr.Slider(
79
- minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold"
80
- ),
81
- gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
82
- ]
83
-
84
- outputs = gr.Image(type="filepath", label="Output Image")
85
- title = "Ultralytics YOLOv8 Segmentation Demo"
86
-
87
- examples = [
88
- ["zidane.jpg", "yolov8m-seg.pt", 640, 0.6, 0.45],
89
- ["highway.jpg", "yolov8m-seg.pt", 640, 0.25, 0.45],
90
- ["small-vehicles1.jpeg", "yolov8m-seg.pt", 640, 0.25, 0.45],
91
- ]
92
- demo_app = gr.Interface(
93
- fn=yolov8_inference,
94
- inputs=inputs,
95
- outputs=outputs,
96
- title=title,
97
- examples=examples,
98
- cache_examples=True,
99
- theme="default",
100
- )
101
- demo_app.launch(debug=True, enable_queue=True)