Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

share resize func

roryclearab679b3e459d
diff --git a/detection/rfdetr.py b/detection/rfdetr.py
index 0262118..63b3a38 100644
--- a/detection/rfdetr.py
+++ b/detection/rfdetr.py
@@ -5,6 +5,7 @@ from tinygrad.nn.state import get_state_dict, load_state_dict, safe_save, safe_l
from tinygrad.helpers import fetch
from tinygrad import Tensor, nn
from tinygrad import TinyJit
+from utils.helpers import resize
COCO_CLASSES = ["","person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","","backpack","umbrella","","","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","","dining table","","","toilet","","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","","book","clock","vase","scissors","teddy bear","hair drier"]
detr_to_yolo = [80, 0, 1, 2, -1, -1, 5, 6, 7, 8, 9, 10, 80, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 80, 24, 25, 80, 80, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 80, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, -1, -1, 59, 80, -1, 80, 80, 61, 80, -1, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 80, 73, 74, 75, 76, 77, 78]
@@ -681,10 +682,4 @@ class seq:
for i in range(self.size):
layer = getattr(self, str(i))
x = layer(x)
- return x
-
-def resize(img, new_size):
- img = img.permute(2,0,1)
- img = Tensor.interpolate(img, size=(new_size[1], new_size[0]), mode='linear', align_corners=False)
- img = img.permute(1, 2, 0)
- return img
+ return x
\ No newline at end of file
diff --git a/detection/yolov9.py b/detection/yolov9.py
index 1c42e54..0d298cf 100644
--- a/detection/yolov9.py
+++ b/detection/yolov9.py
@@ -8,6 +8,7 @@ import numpy as np
from collections import defaultdict
from pathlib import Path
from tinygrad import TinyJit
+from utils.helpers import resize
class Sequential():
def __init__(self, size=0, list=None):
@@ -420,12 +421,6 @@ def clip_boxes(boxes, shape):
boxes[..., [1, 3]] = boxes[..., [1, 3]].clip(0, shape[0])
return boxes
-def resize(img, new_size):
- img = img.permute(2,0,1)
- img = Tensor.interpolate(img, size=(new_size[1], new_size[0]), mode='linear', align_corners=False)
- img = img.permute(1, 2, 0)
- return img
-
def compute_iou_matrix(boxes):
x1s = boxes[:, :, 0]
y1s = boxes[:, :, 1]
diff --git a/utils/helpers.py b/utils/helpers.py
index 4c6569b..0419990 100644
--- a/utils/helpers.py
+++ b/utils/helpers.py
@@ -14,6 +14,7 @@ import threading
import cv2
import numpy as np
BASE_DIR = Path(__file__).parent.parent / "data"
+from tinygrad import Tensor
def send_notif(session_token: str, text=None):
host = "www.clearcam.org"
@@ -116,6 +117,12 @@ def draw_bounding_boxes(orig_img_path, predictions, class_labels):
object_count[class_labels[class_id]] += 1
return orig_img
+def resize(img, new_size):
+ img = img.permute(2,0,1)
+ img = Tensor.interpolate(img, size=(new_size[1], new_size[0]), mode='linear', align_corners=False)
+ img = img.permute(1, 2, 0)
+ return img
+
def export_clip(stream_dir, output_path: Path, live=False, length=5, end=0, start=None):
segments = sorted(stream_dir.glob("*.ts"), key=os.path.getmtime)
recent_segments = deque()