nishantkaushik20 commited on
Commit
85fb59e
·
1 Parent(s): 49c19d2

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +5 -4
  2. app.py +39 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
- title: ObjectTrackingYOLOv8
3
- emoji: 📉
4
- colorFrom: purple
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 3.45.1
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: ObjectTrackingWithYOLOv8
3
+ emoji: 🏢
4
+ colorFrom: red
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 3.42.0
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import supervision as sv
3
+ from ultralytics import YOLO
4
+ import numpy as np
5
+ import cv2 # for video to image conversion
6
+
7
+
8
+ model = YOLO('yolov8s.pt')
9
+ byte_tracker = sv.ByteTrack()
10
+ annotator = sv.BoxAnnotator()
11
+
12
+
13
+ def process_video(frame):
14
+ results = model(frame)[0]
15
+ detections = sv.Detections.from_ultralytics(results)
16
+ detections = byte_tracker.update_with_detections(detections)
17
+ labels = [
18
+ f"#{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
19
+ for _, _, confidence, class_id, tracker_id
20
+ in detections
21
+ ]
22
+ yield annotator.annotate(scene=frame.copy(),
23
+ detections=detections, labels=labels)
24
+
25
+
26
+ title = "Object Tracking (w/ YOLOv8)"
27
+ with gr.Blocks() as io:
28
+ gr.Markdown(f"<center><h1>{title}</h1></center>")
29
+ with gr.Row():
30
+ with gr.Column():
31
+ input_image = gr.Image(source='webcam', streaming=True)
32
+ input_button = gr.Button()
33
+ with gr.Column():
34
+ output_image = gr.Image()
35
+ input_image.change(process_video, inputs=[input_image], outputs=[output_image], show_progress=False)
36
+
37
+ io.queue()
38
+
39
+ io.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ultralytics
2
+ supervision