Spaces:
Runtime error
Runtime error
Khunndev Cursor commited on
Commit ·
e3b60de
1
Parent(s): c9976d7
Improve recall for dense mixed-size bundles with adaptive post-processing.
Browse files- detect.py +5 -5
- frontend/src/lib/constants.ts +17 -9
- frontend/src/lib/postprocess.ts +49 -32
- postprocess.py +61 -22
detect.py
CHANGED
|
@@ -11,16 +11,16 @@ from pathlib import Path
|
|
| 11 |
from threading import Lock
|
| 12 |
from typing import Any
|
| 13 |
|
| 14 |
-
from postprocess import apply_detection_postprocess
|
| 15 |
|
| 16 |
STATIC_PATH = Path(__file__).resolve().parent / "static"
|
| 17 |
MODEL_DIR = STATIC_PATH / "models"
|
| 18 |
|
| 19 |
INFERENCE_SIZE = 1024
|
| 20 |
INFERENCE_SIZE_SMALL = 640
|
| 21 |
-
CONF_THRESHOLD = 0.
|
| 22 |
-
IOU_THRESHOLD = 0.
|
| 23 |
-
MAX_DET =
|
| 24 |
TILE_OVERLAP = 0.28
|
| 25 |
|
| 26 |
_sessions: dict[str, Any] = {}
|
|
@@ -228,7 +228,7 @@ def detect_bytes(
|
|
| 228 |
mode = "single frame"
|
| 229 |
|
| 230 |
if boxes:
|
| 231 |
-
keep = _nms(boxes, scores)
|
| 232 |
boxes = [boxes[i] for i in keep]
|
| 233 |
scores = [scores[i] for i in keep]
|
| 234 |
boxes, scores = apply_detection_postprocess(
|
|
|
|
| 11 |
from threading import Lock
|
| 12 |
from typing import Any
|
| 13 |
|
| 14 |
+
from postprocess import apply_detection_postprocess, select_nms_iou
|
| 15 |
|
| 16 |
STATIC_PATH = Path(__file__).resolve().parent / "static"
|
| 17 |
MODEL_DIR = STATIC_PATH / "models"
|
| 18 |
|
| 19 |
INFERENCE_SIZE = 1024
|
| 20 |
INFERENCE_SIZE_SMALL = 640
|
| 21 |
+
CONF_THRESHOLD = 0.52
|
| 22 |
+
IOU_THRESHOLD = 0.45
|
| 23 |
+
MAX_DET = 6000
|
| 24 |
TILE_OVERLAP = 0.28
|
| 25 |
|
| 26 |
_sessions: dict[str, Any] = {}
|
|
|
|
| 228 |
mode = "single frame"
|
| 229 |
|
| 230 |
if boxes:
|
| 231 |
+
keep = _nms(boxes, scores, iou_thres=select_nms_iou(len(boxes)))
|
| 232 |
boxes = [boxes[i] for i in keep]
|
| 233 |
scores = [scores[i] for i in keep]
|
| 234 |
boxes, scores = apply_detection_postprocess(
|
frontend/src/lib/constants.ts
CHANGED
|
@@ -3,18 +3,26 @@ export const MODEL_640_URL = '/models/countmodel-640.onnx'
|
|
| 3 |
export const MODEL_INT8_URL = '/models/countmodel-int8.onnx'
|
| 4 |
export const INFERENCE_SIZE = 1024
|
| 5 |
export const INFERENCE_SIZE_SMALL = 640
|
| 6 |
-
/**
|
| 7 |
-
export const CONFIDENCE_THRESHOLD = 0.
|
| 8 |
-
export const IOU_THRESHOLD = 0.
|
|
|
|
|
|
|
|
|
|
| 9 |
export const TILE_OVERLAP = 0.28
|
| 10 |
-
export const MAX_DETECTIONS =
|
| 11 |
-
/** Median-area multipliers for
|
| 12 |
export const BOX_SIZE_LOWER_MULT = 0.35
|
| 13 |
export const BOX_SIZE_UPPER_MULT = 2.8
|
| 14 |
-
/**
|
| 15 |
-
export const
|
| 16 |
-
export const
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
export const GROUP_COLORS = [
|
| 20 |
'#ef4444',
|
|
|
|
| 3 |
export const MODEL_INT8_URL = '/models/countmodel-int8.onnx'
|
| 4 |
export const INFERENCE_SIZE = 1024
|
| 5 |
export const INFERENCE_SIZE_SMALL = 640
|
| 6 |
+
/** Recall-friendly decode; post-process handles precision on sparse scenes. */
|
| 7 |
+
export const CONFIDENCE_THRESHOLD = 0.52
|
| 8 |
+
export const IOU_THRESHOLD = 0.45
|
| 9 |
+
export const IOU_THRESHOLD_DENSE = 0.52
|
| 10 |
+
/** Raw candidates before NMS — above this use denser NMS IoU. */
|
| 11 |
+
export const IOU_RECALL_RAW_COUNT = 1500
|
| 12 |
export const TILE_OVERLAP = 0.28
|
| 13 |
+
export const MAX_DETECTIONS = 6000
|
| 14 |
+
/** Median-area multipliers for uniform bundles only. */
|
| 15 |
export const BOX_SIZE_LOWER_MULT = 0.35
|
| 16 |
export const BOX_SIZE_UPPER_MULT = 2.8
|
| 17 |
+
/** Loose area bounds for dense / mixed-size bundles. */
|
| 18 |
+
export const BOX_SIZE_LOOSE_LOWER = 0.1
|
| 19 |
+
export const BOX_SIZE_LOOSE_UPPER = 12
|
| 20 |
+
/** Skip strict size filter when p90/p10 area ratio exceeds this. */
|
| 21 |
+
export const MIXED_SIZE_RATIO = 3
|
| 22 |
+
/** Skip strict size filter when this many boxes survive NMS. */
|
| 23 |
+
export const DENSE_DETECTION_COUNT = 500
|
| 24 |
+
/** Merge tile duplicates only — fraction of smaller box min side. */
|
| 25 |
+
export const CENTER_MERGE_SIZE_RATIO = 0.28
|
| 26 |
|
| 27 |
export const GROUP_COLORS = [
|
| 28 |
'#ef4444',
|
frontend/src/lib/postprocess.ts
CHANGED
|
@@ -1,32 +1,49 @@
|
|
| 1 |
/**
|
| 2 |
* Shared detection post-processing (no retrain).
|
| 3 |
-
*
|
|
|
|
| 4 |
*/
|
| 5 |
import type { RawDetection } from './nms'
|
| 6 |
import { filterOutliers, nonMaxSuppression } from './nms'
|
| 7 |
import {
|
|
|
|
|
|
|
| 8 |
BOX_SIZE_LOWER_MULT,
|
| 9 |
BOX_SIZE_UPPER_MULT,
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
IOU_THRESHOLD,
|
|
|
|
| 14 |
MAX_DETECTIONS,
|
|
|
|
| 15 |
} from './constants'
|
| 16 |
|
| 17 |
export { nonMaxSuppression }
|
| 18 |
|
| 19 |
-
function
|
| 20 |
-
if (detections.length
|
| 21 |
-
const
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
)
|
| 27 |
}
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
export function filterBoxSize(
|
| 31 |
detections: RawDetection[],
|
| 32 |
lowerMult = BOX_SIZE_LOWER_MULT,
|
|
@@ -37,47 +54,46 @@ export function filterBoxSize(
|
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
-
* Merge duplicate detections on one pipe (
|
| 41 |
-
*
|
| 42 |
*/
|
| 43 |
-
export function mergeCenterClusters(
|
| 44 |
-
detections: RawDetection[],
|
| 45 |
-
epsPx?: number,
|
| 46 |
-
): RawDetection[] {
|
| 47 |
if (detections.length <= 1) return detections
|
| 48 |
|
| 49 |
-
const eps = epsPx ?? centerMergeEps(detections)
|
| 50 |
-
const epsSq = eps * eps
|
| 51 |
const sorted = [...detections].sort((a, b) => b.confidence - a.confidence)
|
| 52 |
-
const kept: RawDetection
|
| 53 |
-
const centers: Array<{ x: number; y: number }> = []
|
| 54 |
|
| 55 |
for (const det of sorted) {
|
|
|
|
|
|
|
| 56 |
const cx = (det.xmin + det.xmax) / 2
|
| 57 |
const cy = (det.ymin + det.ymax) / 2
|
|
|
|
| 58 |
let duplicate = false
|
| 59 |
-
for (const
|
| 60 |
-
const dx = cx -
|
| 61 |
-
const dy = cy -
|
| 62 |
-
|
|
|
|
| 63 |
duplicate = true
|
| 64 |
break
|
| 65 |
}
|
| 66 |
}
|
| 67 |
if (!duplicate) {
|
| 68 |
-
kept.push(det)
|
| 69 |
-
centers.push({ x: cx, y: cy })
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
-
return kept
|
| 74 |
}
|
| 75 |
|
| 76 |
export function applyDetectionPostProcess(
|
| 77 |
detections: RawDetection[],
|
| 78 |
options?: { extraOutlierFilter?: boolean },
|
| 79 |
): RawDetection[] {
|
| 80 |
-
let out =
|
|
|
|
|
|
|
| 81 |
out = mergeCenterClusters(out)
|
| 82 |
if (options?.extraOutlierFilter) {
|
| 83 |
out = filterOutliers(out)
|
|
@@ -96,6 +112,7 @@ export function postProcessPipeline(
|
|
| 96 |
raw: RawDetection[],
|
| 97 |
options?: { extraOutlierFilter?: boolean },
|
| 98 |
): RawDetection[] {
|
| 99 |
-
const
|
|
|
|
| 100 |
return applyDetectionPostProcess(nms, options)
|
| 101 |
}
|
|
|
|
| 1 |
/**
|
| 2 |
* Shared detection post-processing (no retrain).
|
| 3 |
+
* Adaptive for dense / mixed-size bundles: looser NMS, skip median size filter,
|
| 4 |
+
* size-aware duplicate merge (tiling only).
|
| 5 |
*/
|
| 6 |
import type { RawDetection } from './nms'
|
| 7 |
import { filterOutliers, nonMaxSuppression } from './nms'
|
| 8 |
import {
|
| 9 |
+
BOX_SIZE_LOOSE_LOWER,
|
| 10 |
+
BOX_SIZE_LOOSE_UPPER,
|
| 11 |
BOX_SIZE_LOWER_MULT,
|
| 12 |
BOX_SIZE_UPPER_MULT,
|
| 13 |
+
CENTER_MERGE_SIZE_RATIO,
|
| 14 |
+
DENSE_DETECTION_COUNT,
|
| 15 |
+
IOU_RECALL_RAW_COUNT,
|
| 16 |
IOU_THRESHOLD,
|
| 17 |
+
IOU_THRESHOLD_DENSE,
|
| 18 |
MAX_DETECTIONS,
|
| 19 |
+
MIXED_SIZE_RATIO,
|
| 20 |
} from './constants'
|
| 21 |
|
| 22 |
export { nonMaxSuppression }
|
| 23 |
|
| 24 |
+
export function sizeDiversityRatio(detections: RawDetection[]): number {
|
| 25 |
+
if (detections.length < 10) return 1
|
| 26 |
+
const areas = detections
|
| 27 |
+
.map((d) => (d.xmax - d.xmin) * (d.ymax - d.ymin))
|
| 28 |
+
.sort((a, b) => a - b)
|
| 29 |
+
const p10 = areas[Math.floor(areas.length * 0.1)]
|
| 30 |
+
const p90 = areas[Math.floor(areas.length * 0.9)]
|
| 31 |
+
return p90 / Math.max(p10, 1)
|
| 32 |
}
|
| 33 |
|
| 34 |
+
export function selectNmsIou(rawCount: number): number {
|
| 35 |
+
if (rawCount >= IOU_RECALL_RAW_COUNT) return IOU_THRESHOLD_DENSE
|
| 36 |
+
if (rawCount >= 600) return 0.48
|
| 37 |
+
return IOU_THRESHOLD
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function shouldApplyStrictBoxFilter(detections: RawDetection[]): boolean {
|
| 41 |
+
if (detections.length >= DENSE_DETECTION_COUNT) return false
|
| 42 |
+
if (sizeDiversityRatio(detections) >= MIXED_SIZE_RATIO) return false
|
| 43 |
+
return true
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/** Drop boxes much smaller/larger than the typical pipe end (uniform bundles only). */
|
| 47 |
export function filterBoxSize(
|
| 48 |
detections: RawDetection[],
|
| 49 |
lowerMult = BOX_SIZE_LOWER_MULT,
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
+
* Merge duplicate detections on one pipe (tiling overlap).
|
| 58 |
+
* Uses per-box size so neighbours in dense packs are not merged.
|
| 59 |
*/
|
| 60 |
+
export function mergeCenterClusters(detections: RawDetection[]): RawDetection[] {
|
|
|
|
|
|
|
|
|
|
| 61 |
if (detections.length <= 1) return detections
|
| 62 |
|
|
|
|
|
|
|
| 63 |
const sorted = [...detections].sort((a, b) => b.confidence - a.confidence)
|
| 64 |
+
const kept: Array<RawDetection & { cx: number; cy: number; minDim: number }> = []
|
|
|
|
| 65 |
|
| 66 |
for (const det of sorted) {
|
| 67 |
+
const w = det.xmax - det.xmin
|
| 68 |
+
const h = det.ymax - det.ymin
|
| 69 |
const cx = (det.xmin + det.xmax) / 2
|
| 70 |
const cy = (det.ymin + det.ymax) / 2
|
| 71 |
+
const minDim = Math.min(w, h)
|
| 72 |
let duplicate = false
|
| 73 |
+
for (const k of kept) {
|
| 74 |
+
const dx = cx - k.cx
|
| 75 |
+
const dy = cy - k.cy
|
| 76 |
+
const thresh = CENTER_MERGE_SIZE_RATIO * Math.min(minDim, k.minDim)
|
| 77 |
+
if (dx * dx + dy * dy < thresh * thresh) {
|
| 78 |
duplicate = true
|
| 79 |
break
|
| 80 |
}
|
| 81 |
}
|
| 82 |
if (!duplicate) {
|
| 83 |
+
kept.push({ ...det, cx, cy, minDim })
|
|
|
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
+
return kept.map(({ cx: _cx, cy: _cy, minDim: _m, ...det }) => det)
|
| 88 |
}
|
| 89 |
|
| 90 |
export function applyDetectionPostProcess(
|
| 91 |
detections: RawDetection[],
|
| 92 |
options?: { extraOutlierFilter?: boolean },
|
| 93 |
): RawDetection[] {
|
| 94 |
+
let out = shouldApplyStrictBoxFilter(detections)
|
| 95 |
+
? filterBoxSize(detections)
|
| 96 |
+
: filterOutliers(detections, BOX_SIZE_LOOSE_LOWER, BOX_SIZE_LOOSE_UPPER)
|
| 97 |
out = mergeCenterClusters(out)
|
| 98 |
if (options?.extraOutlierFilter) {
|
| 99 |
out = filterOutliers(out)
|
|
|
|
| 112 |
raw: RawDetection[],
|
| 113 |
options?: { extraOutlierFilter?: boolean },
|
| 114 |
): RawDetection[] {
|
| 115 |
+
const iou = selectNmsIou(raw.length)
|
| 116 |
+
const nms = nonMaxSuppression(raw, iou, MAX_DETECTIONS)
|
| 117 |
return applyDetectionPostProcess(nms, options)
|
| 118 |
}
|
postprocess.py
CHANGED
|
@@ -3,20 +3,39 @@ from __future__ import annotations
|
|
| 3 |
|
| 4 |
BOX_SIZE_LOWER_MULT = 0.35
|
| 5 |
BOX_SIZE_UPPER_MULT = 2.8
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
-
def
|
| 12 |
-
if len(boxes) <
|
| 13 |
-
return
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def filter_box_size(
|
|
@@ -40,36 +59,53 @@ def filter_box_size(
|
|
| 40 |
return out_boxes, out_scores
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def merge_center_clusters(
|
| 44 |
boxes: list,
|
| 45 |
scores: list,
|
| 46 |
-
eps_px: float | None = None,
|
| 47 |
) -> tuple[list, list]:
|
| 48 |
if len(boxes) <= 1:
|
| 49 |
return boxes, scores
|
| 50 |
|
| 51 |
-
eps = eps_px if eps_px is not None else _center_merge_eps(boxes)
|
| 52 |
-
eps_sq = eps * eps
|
| 53 |
order = sorted(range(len(boxes)), key=lambda i: scores[i], reverse=True)
|
| 54 |
kept_boxes: list = []
|
| 55 |
kept_scores: list = []
|
| 56 |
-
|
| 57 |
|
| 58 |
for i in order:
|
| 59 |
b = boxes[i]
|
|
|
|
|
|
|
| 60 |
cx = (b[0] + b[2]) / 2
|
| 61 |
cy = (b[1] + b[3]) / 2
|
|
|
|
| 62 |
duplicate = False
|
| 63 |
-
for
|
| 64 |
-
dx = cx -
|
| 65 |
-
dy = cy -
|
| 66 |
-
|
|
|
|
| 67 |
duplicate = True
|
| 68 |
break
|
| 69 |
if not duplicate:
|
| 70 |
kept_boxes.append(b)
|
| 71 |
kept_scores.append(scores[i])
|
| 72 |
-
|
| 73 |
|
| 74 |
return kept_boxes, kept_scores
|
| 75 |
|
|
@@ -81,7 +117,10 @@ def apply_detection_postprocess(
|
|
| 81 |
extra_outlier_filter: bool = False,
|
| 82 |
filter_outliers_fn=None,
|
| 83 |
) -> tuple[list, list]:
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
| 85 |
boxes, scores = merge_center_clusters(boxes, scores)
|
| 86 |
if extra_outlier_filter and filter_outliers_fn and boxes:
|
| 87 |
keep = filter_outliers_fn(boxes)
|
|
|
|
| 3 |
|
| 4 |
BOX_SIZE_LOWER_MULT = 0.35
|
| 5 |
BOX_SIZE_UPPER_MULT = 2.8
|
| 6 |
+
BOX_SIZE_LOOSE_LOWER = 0.1
|
| 7 |
+
BOX_SIZE_LOOSE_UPPER = 12.0
|
| 8 |
+
MIXED_SIZE_RATIO = 3.0
|
| 9 |
+
DENSE_DETECTION_COUNT = 500
|
| 10 |
+
CENTER_MERGE_SIZE_RATIO = 0.28
|
| 11 |
+
IOU_THRESHOLD = 0.45
|
| 12 |
+
IOU_THRESHOLD_DENSE = 0.52
|
| 13 |
+
IOU_RECALL_RAW_COUNT = 1500
|
| 14 |
|
| 15 |
|
| 16 |
+
def size_diversity_ratio(boxes: list) -> float:
|
| 17 |
+
if len(boxes) < 10:
|
| 18 |
+
return 1.0
|
| 19 |
+
areas = sorted((b[2] - b[0]) * (b[3] - b[1]) for b in boxes)
|
| 20 |
+
p10 = areas[int(len(areas) * 0.1)]
|
| 21 |
+
p90 = areas[int(len(areas) * 0.9)]
|
| 22 |
+
return p90 / max(p10, 1.0)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def select_nms_iou(raw_count: int) -> float:
|
| 26 |
+
if raw_count >= IOU_RECALL_RAW_COUNT:
|
| 27 |
+
return IOU_THRESHOLD_DENSE
|
| 28 |
+
if raw_count >= 600:
|
| 29 |
+
return 0.48
|
| 30 |
+
return IOU_THRESHOLD
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _should_apply_strict_box_filter(boxes: list) -> bool:
|
| 34 |
+
if len(boxes) >= DENSE_DETECTION_COUNT:
|
| 35 |
+
return False
|
| 36 |
+
if size_diversity_ratio(boxes) >= MIXED_SIZE_RATIO:
|
| 37 |
+
return False
|
| 38 |
+
return True
|
| 39 |
|
| 40 |
|
| 41 |
def filter_box_size(
|
|
|
|
| 59 |
return out_boxes, out_scores
|
| 60 |
|
| 61 |
|
| 62 |
+
def _filter_loose(boxes: list, scores: list) -> tuple[list, list]:
|
| 63 |
+
if len(boxes) < 3:
|
| 64 |
+
return boxes, scores
|
| 65 |
+
areas = [(b[2] - b[0]) * (b[3] - b[1]) for b in boxes]
|
| 66 |
+
sorted_areas = sorted(areas)
|
| 67 |
+
median = sorted_areas[len(sorted_areas) // 2]
|
| 68 |
+
lo = median * BOX_SIZE_LOOSE_LOWER
|
| 69 |
+
hi = median * BOX_SIZE_LOOSE_UPPER
|
| 70 |
+
out_boxes, out_scores = [], []
|
| 71 |
+
for b, s, a in zip(boxes, scores, areas):
|
| 72 |
+
if lo <= a <= hi:
|
| 73 |
+
out_boxes.append(b)
|
| 74 |
+
out_scores.append(s)
|
| 75 |
+
return out_boxes, out_scores
|
| 76 |
+
|
| 77 |
+
|
| 78 |
def merge_center_clusters(
|
| 79 |
boxes: list,
|
| 80 |
scores: list,
|
|
|
|
| 81 |
) -> tuple[list, list]:
|
| 82 |
if len(boxes) <= 1:
|
| 83 |
return boxes, scores
|
| 84 |
|
|
|
|
|
|
|
| 85 |
order = sorted(range(len(boxes)), key=lambda i: scores[i], reverse=True)
|
| 86 |
kept_boxes: list = []
|
| 87 |
kept_scores: list = []
|
| 88 |
+
meta: list[tuple[float, float, float]] = []
|
| 89 |
|
| 90 |
for i in order:
|
| 91 |
b = boxes[i]
|
| 92 |
+
w = b[2] - b[0]
|
| 93 |
+
h = b[3] - b[1]
|
| 94 |
cx = (b[0] + b[2]) / 2
|
| 95 |
cy = (b[1] + b[3]) / 2
|
| 96 |
+
min_dim = min(w, h)
|
| 97 |
duplicate = False
|
| 98 |
+
for kx, ky, kmin in meta:
|
| 99 |
+
dx = cx - kx
|
| 100 |
+
dy = cy - ky
|
| 101 |
+
thresh = CENTER_MERGE_SIZE_RATIO * min(min_dim, kmin)
|
| 102 |
+
if dx * dx + dy * dy < thresh * thresh:
|
| 103 |
duplicate = True
|
| 104 |
break
|
| 105 |
if not duplicate:
|
| 106 |
kept_boxes.append(b)
|
| 107 |
kept_scores.append(scores[i])
|
| 108 |
+
meta.append((cx, cy, min_dim))
|
| 109 |
|
| 110 |
return kept_boxes, kept_scores
|
| 111 |
|
|
|
|
| 117 |
extra_outlier_filter: bool = False,
|
| 118 |
filter_outliers_fn=None,
|
| 119 |
) -> tuple[list, list]:
|
| 120 |
+
if _should_apply_strict_box_filter(boxes):
|
| 121 |
+
boxes, scores = filter_box_size(boxes, scores)
|
| 122 |
+
else:
|
| 123 |
+
boxes, scores = _filter_loose(boxes, scores)
|
| 124 |
boxes, scores = merge_center_clusters(boxes, scores)
|
| 125 |
if extra_outlier_filter and filter_outliers_fn and boxes:
|
| 126 |
keep = filter_outliers_fn(boxes)
|