Upload 6 files
Browse files- app.py +57 -0
- best.pt +3 -0
- examples/example1.jpg +0 -0
- examples/example2.jpg +0 -0
- examples/example3.jpg +0 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import PIL.Image as Image
|
4 |
+
|
5 |
+
from ultralytics import YOLO
|
6 |
+
|
7 |
+
model = YOLO("best.pt")
|
8 |
+
|
9 |
+
|
10 |
+
def predict_image(img, conf_threshold, iou_threshold, image_size):
|
11 |
+
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
12 |
+
results = model.predict(
|
13 |
+
source=img,
|
14 |
+
conf=conf_threshold,
|
15 |
+
iou=iou_threshold,
|
16 |
+
show_labels=True,
|
17 |
+
show_conf=True,
|
18 |
+
imgsz=image_size,
|
19 |
+
)
|
20 |
+
|
21 |
+
for r in results:
|
22 |
+
im_array = r.plot()
|
23 |
+
im = Image.fromarray(im_array[..., ::-1])
|
24 |
+
|
25 |
+
return im
|
26 |
+
|
27 |
+
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=predict_image,
|
31 |
+
inputs=[
|
32 |
+
gr.Image(type="pil", label="Upload Image"),
|
33 |
+
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
34 |
+
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
35 |
+
gr.Slider(
|
36 |
+
label="Image Size",
|
37 |
+
minimum=320,
|
38 |
+
maximum=1280,
|
39 |
+
step=32,
|
40 |
+
value=640,
|
41 |
+
)
|
42 |
+
],
|
43 |
+
outputs=gr.Image(type="pil", label="Result"),
|
44 |
+
title="YOLOv10: Real-Time Fire and Smoke Detection",
|
45 |
+
description="This project utilizes the YOLOv10 model to detect Fire and Smoke in Real-Time. Adjust the confidence and IoU thresholds for optimal detection performance. Upload an image to see the detection results.\n [Github](https://github.com/X-Men01/YOLOv10-Fire-and-Smoke-Detection)",
|
46 |
+
examples=[
|
47 |
+
[example_list[0][0], 0.25, 0.45, 640],
|
48 |
+
[example_list[1][0], 0.25, 0.45, 960],
|
49 |
+
[example_list[2][0], 0.25, 0.45, 640],
|
50 |
+
],
|
51 |
+
allow_flagging="never",
|
52 |
+
submit_btn="Run Inference",
|
53 |
+
article = "Created at [09. PyTorch Model Deployment](https://www.learnpytorch.io/09_pytorch_model_deployment/)."
|
54 |
+
)
|
55 |
+
|
56 |
+
if __name__ == "__main__":
|
57 |
+
iface.launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5f4bf49497480dcb78baeeefbf12119e4b45344d5644aa2bbed1a20017e14ca8
|
3 |
+
size 64111730
|
examples/example1.jpg
ADDED
examples/example2.jpg
ADDED
examples/example3.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ultralytics==8.2.56
|
2 |
+
gradio==3.1.4
|