2lu commited on
Commit
e9b6d8d
·
1 Parent(s): 2a10374

yolov8 accident detector

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +73 -0
  3. best.pt +3 -0
  4. requirements.txt +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ best.pt filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from ultralyticsplus import YOLO, render_result
4
+
5
+ def yolov8_func(image):
6
+ #image_size: gr.inputs.Slider = 640,
7
+ #conf_threshold: gr.inputs.Slider = 0.4,
8
+ #iou_threshold: gr.inputs.Slider = 0.50):
9
+
10
+ model_path = "best.pt"
11
+ model = YOLO(model_path)
12
+
13
+ results = model.predict(image,
14
+ conf = 0.4,
15
+ iou = 0.6,
16
+ imgsz = 640)
17
+
18
+ box = results[0].boxes
19
+
20
+ print("Object type: ", box.cls)
21
+ print("Coordinates: ", box.xyxy)
22
+ print("Probability: ", box.conf)
23
+
24
+ render = render_result(model=model, image=image, result=results[0])
25
+
26
+ return render
27
+
28
+ # inputs = [
29
+ # gr.inputs.Image(type="filepath", label="Input Image"),
30
+ # gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
31
+ # gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
32
+ # gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="Iou Threshold")
33
+ # ]
34
+
35
+ # gr.HTML
36
+ # outputs = gr.outputs.Image(type="filepath", label="Output Image")
37
+
38
+ # yolo_app = gr.Interface(
39
+ # fn=yolov8_func,
40
+ # inputs=inputs,
41
+ # outputs=outputs,
42
+ # title="Accident detector",
43
+ # )
44
+
45
+ # yolo_app.launch(debug=True, enable_queue=True)
46
+
47
+ with gr.Blocks(title="YOLOS Object Detection - ClassCat", css=".gradio-container {background:lightyellow;}") as demo:
48
+ gr.HTML('<h1>Yolo Object Detection</h1>')
49
+ #gr.HTML("<h4>supported objects are [aeroplane,bicycle,bird,boat,bottle,bus,car,cat,chair,cow,diningtable,dog,horse,motorbike,person,pottedplant,sheep,sofa,train,tvmonitor]</h4>")
50
+ gr.HTML("<br>")
51
+ with gr.Row():
52
+ input_image = gr.Image(label="Input image", type="pil")
53
+ output_image = gr.Image(label="Output image", type="pil")
54
+ gr.HTML("<br>")
55
+ #gr.HTML("<h4>object centre detection threshold means the object centre will be considered a new object if it's value is above threshold</h4>")
56
+ #gr.HTML("<p>less means more objects</p>")
57
+ #gr.HTML("<h4>bounding box threshold is IOU value threshold. If intersection/union area of two bounding boxes are greater than threshold value the one box will be suppressed</h4>")
58
+ #gr.HTML("<p>more means more bounding boxes<p>")
59
+ #gr.HTML("<br>")
60
+
61
+ #obj_threshold = gr.Slider(0, 1.0, value=0.2, label=' object centre detection threshold')
62
+ #gr.HTML("<br>")
63
+ #bb_threshold = gr.Slider(0, 1.0, value=0.3, label=' bounding box draw threshold')
64
+ #gr.HTML("<br>")
65
+
66
+ send_btn = gr.Button("Detect")
67
+ gr.HTML("<br>")
68
+ #gr.Examples(['./samples/out_1.jpg'], inputs=input_image)
69
+
70
+ send_btn.click(fn=yolov8_func, inputs=[input_image], outputs=[output_image])
71
+
72
+
73
+ demo.launch(debug=True)
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fa294fcc7b5de8d86155a0370f2336cee784b459552104ca25904aee740ded7
3
+ size 6233753
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==4.16.0
2
+ torch==2.1.2
3
+ ultralyticsplus==0.0.29