Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
426db83
1
Parent(s):
3358b10
remove cv2 import
Browse files- app.py +4 -13
- requirement.txt +0 -1
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import time
|
3 |
|
4 |
-
import cv2
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
import spaces
|
@@ -41,16 +40,6 @@ def annotate_image(input_image, detections, labels) -> np.ndarray:
|
|
41 |
return output_image
|
42 |
|
43 |
|
44 |
-
def resize_to_max_side(frame: np.ndarray, max_side: int = 640):
|
45 |
-
h, w = frame.shape[:2]
|
46 |
-
if h > w:
|
47 |
-
new_h, new_w = max_side, int(w * max_side / h)
|
48 |
-
else:
|
49 |
-
new_h, new_w = int(h * max_side / w), max_side
|
50 |
-
|
51 |
-
return cv2.resize(frame, (new_w, new_h))
|
52 |
-
|
53 |
-
|
54 |
@spaces.GPU
|
55 |
def process_video(
|
56 |
input_video,
|
@@ -102,8 +91,10 @@ def process_video(
|
|
102 |
|
103 |
|
104 |
def query(frame, classes, confidence_threshold, max_side=360):
|
105 |
-
frame_resized =
|
106 |
-
|
|
|
|
|
107 |
inputs = processor(images=image, text=classes, return_tensors="pt").to(device)
|
108 |
with torch.no_grad():
|
109 |
start = time.time()
|
|
|
1 |
import os
|
2 |
import time
|
3 |
|
|
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
import spaces
|
|
|
40 |
return output_image
|
41 |
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
@spaces.GPU
|
44 |
def process_video(
|
45 |
input_video,
|
|
|
91 |
|
92 |
|
93 |
def query(frame, classes, confidence_threshold, max_side=360):
|
94 |
+
frame_resized = sv.resize_image(
|
95 |
+
image=frame, resolution_wh=(max_side, max_side), keep_aspect_ratio=True
|
96 |
+
)
|
97 |
+
image = Image.fromarray(frame_resized)
|
98 |
inputs = processor(images=image, text=classes, return_tensors="pt").to(device)
|
99 |
with torch.no_grad():
|
100 |
start = time.time()
|
requirement.txt
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
torch
|
2 |
timm
|
3 |
-
opencv-python
|
4 |
git+https://github.com/yonigozlan/transformers.git@add-om-det-turbo
|
5 |
supervision
|
6 |
spaces
|
|
|
1 |
torch
|
2 |
timm
|
|
|
3 |
git+https://github.com/yonigozlan/transformers.git@add-om-det-turbo
|
4 |
supervision
|
5 |
spaces
|