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

yolov8 accident detector

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,7 +1,9 @@
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,
@@ -18,12 +20,12 @@ def yolov8_func(image):
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"),
@@ -51,6 +53,7 @@ with gr.Blocks(title="YOLOS Object Detection - ClassCat", css=".gradio-container
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>")
@@ -67,7 +70,7 @@ with gr.Blocks(title="YOLOS Object Detection - ClassCat", css=".gradio-container
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)
 
1
  import gradio as gr
2
+ # import torch
3
  from ultralyticsplus import YOLO, render_result
4
 
5
+ classes: ['car', 'bike', 'person', 'car_car_accident', 'car_bike_accident', 'car_person_accident', 'bike_bike_accidnet', 'bike_person_accident', 'car_object_accident', 'bike_object_accident']
6
+
7
  def yolov8_func(image):
8
  #image_size: gr.inputs.Slider = 640,
9
  #conf_threshold: gr.inputs.Slider = 0.4,
 
20
  box = results[0].boxes
21
 
22
  print("Object type: ", box.cls)
23
+ # print("Coordinates: ", box.xyxy)
24
+ # print("Probability: ", box.conf)
25
 
26
  render = render_result(model=model, image=image, result=results[0])
27
 
28
+ return render, box.cls
29
 
30
  # inputs = [
31
  # gr.inputs.Image(type="filepath", label="Input Image"),
 
53
  with gr.Row():
54
  input_image = gr.Image(label="Input image", type="pil")
55
  output_image = gr.Image(label="Output image", type="pil")
56
+ output_label = gr.Text(label="output label")
57
  gr.HTML("<br>")
58
  #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>")
59
  #gr.HTML("<p>less means more objects</p>")
 
70
  gr.HTML("<br>")
71
  #gr.Examples(['./samples/out_1.jpg'], inputs=input_image)
72
 
73
+ send_btn.click(fn=yolov8_func, inputs=[input_image], outputs=[output_image, output_label])
74
 
75
 
76
  demo.launch(debug=True)