scorevision: push artifact
Browse files123428 unmodified lines333435363738394041125 unmodified lines16716816917017117217337 unmodified lines2112122132142152162175 unmodified lines22322422522622722822923023123223323423523623723823924021 unmodified lines262263264265266267268"""ScoreVision crime detector — YOLOv11s with flip TTA + per-class conf + cross-class NMS."""from pathlib import Pathimport math28 unmodified linescross_iou_thresh = 0.50max_aspect_ratio = 10.0max_det = 150# tuned on held-out SAM3-labeled crime set_conf_thres_array = np.array([0.50, 0.50, 0.30, 0.30, 0.40, 0.40], dtype=np.float32)def __init__(self, path_hf_repo: Path) -> None:125 unmodified linesreturn np.array(keep_all, dtype=np.intp)def _cross_class_dedup(self, boxes, scores, cls_ids, iou_thr):"""If two boxes (any class) heavily overlap, keep only the higher-scoring one."""n = len(boxes)if n == 0:return np.array([], dtype=np.intp)37 unmodified linesdef _decode(self, preds: ndarray, ratio: float, pad: tuple[float, float],orig_size: tuple[int, int]) -> tuple[np.ndarray, np.ndarray, np.ndarray]:"""ONNX output is [1,300,6]: x1,y1,x2,y2,conf,cls in letterboxed coords."""if preds.ndim == 3 and preds.shape[0] == 1:preds = preds[0]if preds.ndim != 2 or preds.shape[1] < 6:5 unmodified linesboxes = preds[:, :4].astype(np.float32)scores = preds[:, 4].astype(np.float32)cls_ids = preds[:, 5].astype(np.int32)# drop padded rowskeep = (scores > 0) & (cls_ids >= 0) & (cls_ids < len(self.class_names))boxes, scores, cls_ids = boxes[keep], scores[keep], cls_ids[keep]if len(boxes) == 0:return boxes, scores, cls_ids# per-class confidencethr = self._conf_thres_array[cls_ids]keep = scores >= thrboxes, scores, cls_ids = boxes[keep], scores[keep], cls_ids[keep]if len(boxes) == 0:return boxes, scores, cls_ids# untransform: subtract pad, divide ratiopad_w, pad_h = padboxes[:, [0, 2]] -= pad_wboxes[:, [1, 3]] -= pad_h21 unmodified linescls_ids = np.concatenate([c0, cf], axis=0) if len(b0) or len(bf) else c0if len(boxes) == 0:return []# filter + per-class NMS + cross-class dedupboxes, scores, cls_ids = self._filter_sane(boxes, scores, cls_ids, (image.shape[1], image.shape[0]))1234528 unmodified lines343536373839404142125 unmodified lines16816917017117217337 unmodified lines2112122132142152165 unmodified lines22222322422522622722822923023123223323423523621 unmodified lines258259260261262263"""ScoreVision crime detector v24 — YOLOv11s trained on rival-consensus labels.Per-class conf thresholds tuned vs validator-PGT proxy; flip TTA; cross-class NMS."""from pathlib import Pathimport math28 unmodified linescross_iou_thresh = 0.50max_aspect_ratio = 10.0max_det = 150# per-class thresholds — tuned on rival-consensus GT (proxy for validator PGT)_conf_thres_array = np.array([0.30, 0.70, 0.60, 0.50, 0.40, 0.40], dtype=np.float32)def __init__(self, path_hf_repo: Path) -> None:125 unmodified linesreturn np.array(keep_all, dtype=np.intp)def _cross_class_dedup(self, boxes, scores, cls_ids, iou_thr):n = len(boxes)if n == 0:return np.array([], dtype=np.intp)37 unmodified linesdef _decode(self, preds: ndarray, ratio: float, pad: tuple[float, float],orig_size: tuple[int, int]) -> tuple[np.ndarray, np.ndarray, np.ndarray]:if preds.ndim == 3 and preds.shape[0] == 1:preds = preds[0]if preds.ndim != 2 or preds.shape[1] < 6:5 unmodified linesboxes = preds[:, :4].astype(np.float32)scores = preds[:, 4].astype(np.float32)cls_ids = preds[:, 5].astype(np.int32)keep = (scores > 0) & (cls_ids >= 0) & (cls_ids < len(self.class_names))boxes, scores, cls_ids = boxes[keep], scores[keep], cls_ids[keep]if len(boxes) == 0:return boxes, scores, cls_idsthr = self._conf_thres_array[cls_ids]keep = scores >= thrboxes, scores, cls_ids = boxes[keep], scores[keep], cls_ids[keep]if len(boxes) == 0:return boxes, scores, cls_idspad_w, pad_h = padboxes[:, [0, 2]] -= pad_wboxes[:, [1, 3]] -= pad_h21 unmodified linescls_ids = np.concatenate([c0, cf], axis=0) if len(b0) or len(bf) else c0if len(boxes) == 0:return []boxes, scores, cls_ids = self._filter_sane(boxes, scores, cls_ids, (image.shape[1], image.shape[0]))
miner.py+4-9