what are these
This commit is contained in:
1 parent
538276a5f0
commit
34bee8bf31
8 files changed
+288
-9
No files matched your search
@@ -148,6 +148,7 @@ class APIPersonDetector(APIStageBase):
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
|
||||
|
||||
# haiku 4.5 is multimodal but i fear its going to ping 65 million images per second (we need cache control? who are we? why cant we upload video?)
|
||||
class VLMVerifier(APIStageBase):
|
||||
"""
|
||||
|
||||
@@ -5,7 +5,12 @@ import time
|
||||
from typing import List, Optional
|
||||
|
||||
from pipeline.config import DEFAULT_CONFIG, PipelineConfig
|
||||
from pipeline.ops import nms_by_class
|
||||
from pipeline.ops import (
|
||||
merge_overlapping,
|
||||
nms_by_class,
|
||||
select_for_verification,
|
||||
select_top_k,
|
||||
)
|
||||
from pipeline.protocols import Model, Verifier
|
||||
from pipeline.stages.protocol import StageContext, StageResult
|
||||
from pipeline.types import BoundingBox, Detection, Ticket
|
||||
@@ -66,10 +71,39 @@ class LocalCigaretteDetector:
|
||||
cfg = self.cfg
|
||||
h_img, w_img = ctx.frame_data.shape[:2]
|
||||
|
||||
# === Budget: Limit how many people we process ===
|
||||
people_to_process = ctx.people
|
||||
|
||||
if cfg.merge_people:
|
||||
# Merge overlapping people into regions
|
||||
people_to_process = merge_overlapping(
|
||||
people_to_process, cfg.merge_people_iou
|
||||
)
|
||||
if len(people_to_process) < len(ctx.people):
|
||||
logger.debug(
|
||||
"Merged %d people into %d regions",
|
||||
len(ctx.people),
|
||||
len(people_to_process),
|
||||
)
|
||||
|
||||
if cfg.max_person_crops > 0 and len(people_to_process) > cfg.max_person_crops:
|
||||
# Select top K diverse people by priority
|
||||
people_to_process = select_top_k(
|
||||
people_to_process,
|
||||
k=cfg.max_person_crops,
|
||||
priority=cfg.person_priority,
|
||||
)
|
||||
logger.debug(
|
||||
"Budget: Processing %d/%d people (priority=%s)",
|
||||
len(people_to_process),
|
||||
len(ctx.people),
|
||||
cfg.person_priority,
|
||||
)
|
||||
|
||||
all_cigs: List[Detection] = []
|
||||
early_hit = None
|
||||
|
||||
for person in ctx.people:
|
||||
for person in people_to_process:
|
||||
# Expand person box for crop
|
||||
crop_box = self._expand_box(person.box, cfg.person_margin, w_img, h_img)
|
||||
ex1, ey1, ex2, ey2 = crop_box
|
||||
@@ -195,12 +229,28 @@ class LocalVerifier:
|
||||
cfg = self.cfg
|
||||
h_img, w_img = ctx.frame_data.shape[:2]
|
||||
|
||||
# === Budget: Limit how many cigs we verify ===
|
||||
cigs_to_verify = ctx.cigarettes
|
||||
|
||||
if (
|
||||
cfg.max_cig_verifications > 0
|
||||
and len(cigs_to_verify) > cfg.max_cig_verifications
|
||||
):
|
||||
# Select top K by confidence (most likely real → verify first)
|
||||
cigs_to_verify = select_for_verification(
|
||||
cigs_to_verify,
|
||||
k=cfg.max_cig_verifications,
|
||||
min_confidence=cfg.cig_min_confidence,
|
||||
)
|
||||
logger.debug(
|
||||
"Budget: Verifying %d/%d cigarettes",
|
||||
len(cigs_to_verify),
|
||||
len(ctx.cigarettes),
|
||||
)
|
||||
|
||||
confirmed: list[tuple[Detection, float]] = []
|
||||
|
||||
for cig_det in ctx.cigarettes:
|
||||
offset = cig_det.metadata.get("crop_offset", (0, 0))
|
||||
ex1, ey1 = offset
|
||||
|
||||
for cig_det in cigs_to_verify:
|
||||
# Extract padded crop for classifier
|
||||
crop = self._extract_cig_crop(ctx.frame_data, cig_det, w_img, h_img)
|
||||
if crop.size == 0:
|
||||
|
||||
@@ -60,7 +60,7 @@ class StagePipeline:
|
||||
stage.name,
|
||||
ctx.stop_reason,
|
||||
)
|
||||
continue # break?
|
||||
continue # break?
|
||||
|
||||
try:
|
||||
result = stage.process(ctx)
|
||||
|
||||
Reference in new issue
Block a user