Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
8418755
1
Parent(s):
7a4aa57
remove set image size
Browse files
app.py
CHANGED
@@ -44,7 +44,6 @@ def process_video(
|
|
44 |
input_video,
|
45 |
confidence_threshold,
|
46 |
classes,
|
47 |
-
max_side,
|
48 |
progress=gr.Progress(track_tqdm=True),
|
49 |
):
|
50 |
classes = classes.strip(" ").split(",")
|
@@ -61,9 +60,7 @@ def process_video(
|
|
61 |
frame = next(frame_generator)
|
62 |
except StopIteration:
|
63 |
break
|
64 |
-
results, fps = query(
|
65 |
-
frame, classes, confidence_threshold, max_side=max_side
|
66 |
-
)
|
67 |
all_fps.append(fps)
|
68 |
detections = []
|
69 |
|
@@ -92,11 +89,8 @@ def process_video(
|
|
92 |
)
|
93 |
|
94 |
|
95 |
-
def query(frame, classes, confidence_threshold
|
96 |
-
|
97 |
-
image=frame, resolution_wh=(max_side, max_side), keep_aspect_ratio=True
|
98 |
-
)
|
99 |
-
image = Image.fromarray(frame_resized)
|
100 |
inputs = processor(images=image, text=classes, return_tensors="pt").to(device)
|
101 |
with torch.no_grad():
|
102 |
start = time.time()
|
@@ -124,7 +118,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
124 |
"""
|
125 |
)
|
126 |
gr.Markdown(
|
127 |
-
"Simply upload a video, and write the objects you want to detect! You can also play with confidence threshold
|
128 |
)
|
129 |
|
130 |
with gr.Row():
|
@@ -147,29 +141,23 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
147 |
value=0.2,
|
148 |
step=0.05,
|
149 |
)
|
150 |
-
|
151 |
-
label="Image Size",
|
152 |
-
minimum=240,
|
153 |
-
maximum=1080,
|
154 |
-
value=640,
|
155 |
-
step=10,
|
156 |
-
)
|
157 |
with gr.Row():
|
158 |
submit = gr.Button(variant="primary")
|
159 |
|
160 |
example = gr.Examples(
|
161 |
examples=[
|
162 |
-
["./football.mp4", 0.3, "person, ball, shoe"
|
163 |
-
["./cat.mp4", 0.2, "cat"
|
164 |
-
["./safari2.mp4", 0.3, "elephant, giraffe, springbok, zebra"
|
165 |
],
|
166 |
-
inputs=[input_video, conf, classes
|
167 |
outputs=output_video,
|
168 |
)
|
169 |
|
170 |
submit.click(
|
171 |
fn=process_video,
|
172 |
-
inputs=[input_video, conf, classes
|
173 |
outputs=[output_video, actual_fps],
|
174 |
)
|
175 |
|
|
|
44 |
input_video,
|
45 |
confidence_threshold,
|
46 |
classes,
|
|
|
47 |
progress=gr.Progress(track_tqdm=True),
|
48 |
):
|
49 |
classes = classes.strip(" ").split(",")
|
|
|
60 |
frame = next(frame_generator)
|
61 |
except StopIteration:
|
62 |
break
|
63 |
+
results, fps = query(frame, classes, confidence_threshold)
|
|
|
|
|
64 |
all_fps.append(fps)
|
65 |
detections = []
|
66 |
|
|
|
89 |
)
|
90 |
|
91 |
|
92 |
+
def query(frame, classes, confidence_threshold):
|
93 |
+
image = Image.fromarray(frame)
|
|
|
|
|
|
|
94 |
inputs = processor(images=image, text=classes, return_tensors="pt").to(device)
|
95 |
with torch.no_grad():
|
96 |
start = time.time()
|
|
|
118 |
"""
|
119 |
)
|
120 |
gr.Markdown(
|
121 |
+
"Simply upload a video, and write the objects you want to detect! You can also play with confidence threshold or try the examples below. 👇"
|
122 |
)
|
123 |
|
124 |
with gr.Row():
|
|
|
141 |
value=0.2,
|
142 |
step=0.05,
|
143 |
)
|
144 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
with gr.Row():
|
146 |
submit = gr.Button(variant="primary")
|
147 |
|
148 |
example = gr.Examples(
|
149 |
examples=[
|
150 |
+
["./football.mp4", 0.3, "person, ball, shoe"],
|
151 |
+
["./cat.mp4", 0.2, "cat"],
|
152 |
+
["./safari2.mp4", 0.3, "elephant, giraffe, springbok, zebra"],
|
153 |
],
|
154 |
+
inputs=[input_video, conf, classes],
|
155 |
outputs=output_video,
|
156 |
)
|
157 |
|
158 |
submit.click(
|
159 |
fn=process_video,
|
160 |
+
inputs=[input_video, conf, classes],
|
161 |
outputs=[output_video, actual_fps],
|
162 |
)
|
163 |
|