Skip to content

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

remove postprocess

roryclearc72c79d267b0
diff --git a/detection/rfdetr.py b/detection/rfdetr.py
index 0cac2e5..fa1d969 100644
--- a/detection/rfdetr.py
+++ b/detection/rfdetr.py
@@ -618,7 +618,8 @@ class RFDETR():
labels = topk_indexes % out_logits.shape[2]
boxes = box_cxcywh_to_xyxy(out_bbox)
boxes = Tensor.gather(boxes, 1, topk_boxes.unsqueeze(-1).repeat(1,1,4))
- return Tensor.cat(boxes.squeeze(0), topk_values.squeeze(0).unsqueeze(1), labels.squeeze(0).unsqueeze(1), dim=1)
+ ret = Tensor.cat(boxes.squeeze(0), topk_values.squeeze(0).unsqueeze(1), labels.squeeze(0).unsqueeze(1), dim=1)
+ return ret
def predict(self, samples, targets=None):
_, _, h, w = samples.shape
@@ -650,6 +651,22 @@ class RFDETR():
predictions[:,:4] *= [img0_shape[1], img0_shape[0], img0_shape[1], img0_shape[0]]
return predictions
+def compute_iou_matrix(boxes):
+ x1s = boxes[:, :, 0]
+ y1s = boxes[:, :, 1]
+ x2s = boxes[:, :, 2]
+ y2s = boxes[:, :, 3]
+ areas = (x2s - x1s) * (y2s - y1s)
+ x1 = Tensor.maximum(x1s[:, :, None], x1s[:, None, :])
+ y1 = Tensor.maximum(y1s[:, :, None], y1s[:, None, :])
+ x2 = Tensor.minimum(x2s[:, :, None], x2s[:, None, :])
+ y2 = Tensor.minimum(y2s[:, :, None], y2s[:, None, :])
+ w = Tensor.maximum(Tensor(0), x2 - x1)
+ h = Tensor.maximum(Tensor(0), y2 - y1)
+ intersection = w * h
+ union = areas[:, :, None] + areas[:, None, :] - intersection
+ return intersection / union
+
def box_cxcywh_to_xyxy(x):
x_c, y_c, w, h = [t.squeeze(-1) for t in x.split(1, dim=-1)]
w_pos = w.clip(0.0, float("inf"))