Spaces:
Sleeping
Sleeping
Commit
·
ca3acbe
1
Parent(s):
112da47
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,9 @@ import time
|
|
3 |
import cv2 # opencv2 package for python.
|
4 |
import torch
|
5 |
from pytube import YouTube
|
6 |
-
|
|
|
|
|
7 |
|
8 |
segmentor = pipeline("image-segmentation", model="facebook/detr-resnet-50-panoptic")
|
9 |
|
@@ -22,6 +24,7 @@ def load(URL):
|
|
22 |
frame_fps = (player.get(cv2.CAP_PROP_FPS))
|
23 |
tog = 0
|
24 |
return vid_cap,frame_num,frame_count,frame_fps,tog
|
|
|
25 |
|
26 |
def fw_fn(cur,last):
|
27 |
next = cur+1
|
@@ -43,15 +46,33 @@ def pl_fn(cap,cur,last,fps,pl_tog):
|
|
43 |
ret, frame_bgr = player.read(cur)
|
44 |
frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
45 |
output = segmentor(frame)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
|
|
|
|
|
|
|
|
|
|
47 |
if pl_tog ==1:
|
48 |
cur+=1
|
49 |
else:
|
50 |
cur = cur
|
51 |
-
return
|
52 |
|
53 |
with gr.Blocks() as app:
|
54 |
-
gr.Markdown("""<center><h1>
|
55 |
play_state = gr.Markdown("""<right><h7></h7></right>""")
|
56 |
|
57 |
with gr.Row():
|
|
|
3 |
import cv2 # opencv2 package for python.
|
4 |
import torch
|
5 |
from pytube import YouTube
|
6 |
+
from PIL import Image
|
7 |
+
import numpy as np
|
8 |
+
from transformers import pipeline
|
9 |
|
10 |
segmentor = pipeline("image-segmentation", model="facebook/detr-resnet-50-panoptic")
|
11 |
|
|
|
24 |
frame_fps = (player.get(cv2.CAP_PROP_FPS))
|
25 |
tog = 0
|
26 |
return vid_cap,frame_num,frame_count,frame_fps,tog
|
27 |
+
|
28 |
|
29 |
def fw_fn(cur,last):
|
30 |
next = cur+1
|
|
|
46 |
ret, frame_bgr = player.read(cur)
|
47 |
frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
48 |
output = segmentor(frame)
|
49 |
+
for i in range(len(output)):
|
50 |
+
mask = np.array(output[i]['mask'])/255
|
51 |
+
img = np.array(image)
|
52 |
+
img2 = np.zeros_like(img)
|
53 |
+
img2[:,:,0] = mask
|
54 |
+
img2[:,:,1] = mask
|
55 |
+
img2[:,:,2] = mask
|
56 |
+
seg_mix=img/img2
|
57 |
+
|
58 |
+
#seg_out=img2.astype(np.unit8)
|
59 |
+
results=seg_mix.astype(np.uint8)
|
60 |
+
|
61 |
+
|
62 |
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
if pl_tog ==1:
|
69 |
cur+=1
|
70 |
else:
|
71 |
cur = cur
|
72 |
+
return results,cur
|
73 |
|
74 |
with gr.Blocks() as app:
|
75 |
+
gr.Markdown("""<center><h1>Slow Video Object Detection</h1><h4>Gradio and ultralyticsplus/yolov8s</h4><h4>Probably faster on GPU 🤷♂️</h4></center>""")
|
76 |
play_state = gr.Markdown("""<right><h7></h7></right>""")
|
77 |
|
78 |
with gr.Row():
|