Spaces:
Runtime error
Runtime error
Commit
·
3db562a
0
Parent(s):
Duplicate from Future-Tense/Slo-Mo-YOLO-Video
Browse filesCo-authored-by: Future-tense <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +102 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Slo-Mo YOLO8s Video
|
3 |
+
emoji: 🥴
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.18.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
duplicated_from: Future-Tense/Slo-Mo-YOLO-Video
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
import cv2 # opencv2 package for python.
|
4 |
+
import torch
|
5 |
+
from pytube import YouTube
|
6 |
+
from ultralyticsplus import YOLO, render_result
|
7 |
+
|
8 |
+
|
9 |
+
model = YOLO('ultralyticsplus/yolov8s')
|
10 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
11 |
+
URL = "https://www.youtube.com/watch?v=6NBwbKMyzEE" #URL to parse
|
12 |
+
|
13 |
+
# set model parameters
|
14 |
+
model.overrides['conf'] = 0.50 # NMS confidence threshold
|
15 |
+
model.overrides['iou'] = 0.45 # NMS IoU threshold
|
16 |
+
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
17 |
+
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
18 |
+
model.to(device)
|
19 |
+
|
20 |
+
|
21 |
+
def load(URL):
|
22 |
+
|
23 |
+
yt = YouTube(URL)
|
24 |
+
vid_cap = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().last().download(filename="tmp.mp4")
|
25 |
+
global player
|
26 |
+
player = cv2.VideoCapture(vid_cap)
|
27 |
+
frame_num = int(player.get(cv2.CAP_PROP_POS_FRAMES))
|
28 |
+
frame_count = int(player.get(cv2.CAP_PROP_FRAME_COUNT))
|
29 |
+
frame_fps = (player.get(cv2.CAP_PROP_FPS))
|
30 |
+
tog = 0
|
31 |
+
return vid_cap,frame_num,frame_count,frame_fps,tog
|
32 |
+
|
33 |
+
def vid_play(cap,frame_num):
|
34 |
+
assert player.isOpened() # Make sure that their is a stream.
|
35 |
+
player.set(cv2.CAP_PROP_POS_FRAMES, int(frame_num))
|
36 |
+
ret, frame_bgr = player.read(int(frame_num))
|
37 |
+
frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
38 |
+
results = model.predict(frame)
|
39 |
+
render = render_result(model=model, image=frame, result=results[0])
|
40 |
+
return render
|
41 |
+
|
42 |
+
def fw_fn(cur,last):
|
43 |
+
next = cur+1
|
44 |
+
if next > last:
|
45 |
+
next = last
|
46 |
+
return next
|
47 |
+
def bk_fn(cur):
|
48 |
+
next = cur-1
|
49 |
+
if next < 0:
|
50 |
+
next = 0
|
51 |
+
return next
|
52 |
+
def tog_on():
|
53 |
+
return 1,gr.Markdown.update("""<center><h7>Status: Playing 😁</h7></center>""")
|
54 |
+
def tog_off():
|
55 |
+
return 0,gr.Markdown.update("""<center><h7>Status: Stopped 💀</h7></center>""")
|
56 |
+
|
57 |
+
def pl_fn(cap,cur,last,fps,pl_tog):
|
58 |
+
player.set(cv2.CAP_PROP_POS_FRAMES, cur)
|
59 |
+
ret, frame_bgr = player.read(cur)
|
60 |
+
frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
61 |
+
results = model.predict(frame)
|
62 |
+
render = render_result(model=model, image=frame, result=results[0])
|
63 |
+
if pl_tog ==1:
|
64 |
+
cur+=1
|
65 |
+
else:
|
66 |
+
cur = cur
|
67 |
+
return render,cur
|
68 |
+
|
69 |
+
with gr.Blocks() as app:
|
70 |
+
gr.Markdown("""<center><h1>Slow Video Object Detection</h1><h4>Gradio and ultralyticsplus/yolov8s</h4><h4>Probably faster on GPU 🤷♂️</h4></center>""")
|
71 |
+
play_state = gr.Markdown("""<right><h7></h7></right>""")
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
with gr.Column():
|
75 |
+
youtube_url = gr.Textbox(label="YouTube URL",value=f"{URL}")
|
76 |
+
load_button = gr.Button("Load Video")
|
77 |
+
output_win = gr.Video()
|
78 |
+
with gr.Column():
|
79 |
+
with gr.Row():
|
80 |
+
cur_frame = gr.Number(label="Current Frame")
|
81 |
+
fps_frames = gr.Number(label="Video FPS",interactive=False)
|
82 |
+
total_frames = gr.Number(label="Total Frames",interactive=False)
|
83 |
+
#run_button = gr.Button()
|
84 |
+
with gr.Row():
|
85 |
+
bk = gr.Button("<")
|
86 |
+
pl = gr.Button("Play")
|
87 |
+
st = gr.Button("Stop")
|
88 |
+
fw = gr.Button(">")
|
89 |
+
det_win = gr.Image(source="webcam", streaming=True)
|
90 |
+
with gr.Row():
|
91 |
+
pl_tog=gr.Number(visible=False)
|
92 |
+
ins_cnt=gr.Number(visible=False)
|
93 |
+
pl.click(tog_on,None,[pl_tog,play_state],show_progress=False)
|
94 |
+
st.click(tog_off,None,[pl_tog,play_state],show_progress=False)
|
95 |
+
pl_tog.change(pl_fn,[output_win,cur_frame,total_frames,fps_frames,pl_tog],[det_win,cur_frame],show_progress=False)
|
96 |
+
cur_frame.change(pl_fn,[output_win,cur_frame,total_frames,fps_frames,pl_tog],[det_win,cur_frame],show_progress=False)
|
97 |
+
bk.click(bk_fn,[cur_frame],cur_frame,show_progress=False)
|
98 |
+
fw.click(fw_fn,[cur_frame,total_frames],cur_frame,show_progress=False)
|
99 |
+
load_button.click(load,youtube_url,[output_win,cur_frame,total_frames,fps_frames,pl_tog])
|
100 |
+
#run_button.click(vid_play, [output_win,cur_frame], det_win)
|
101 |
+
|
102 |
+
app.queue(concurrency_count=10).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
opencv-python
|
3 |
+
pytube
|
4 |
+
ultralyticsplus==0.0.14
|