what is blessing my ears rn
This commit is contained in:
1 parent
02e00cbaa2
commit
8f6c3969c0
7 files changed
+28
-411
No files matched your search
+26
-14
@@ -114,11 +114,8 @@ class SmokingDetectionPipeline:
|
||||
self.current_future = self.executor.submit(self._run_inference, frame)
|
||||
|
||||
# 3. Apply cached detections to current frame for visualization
|
||||
# This ensures smooth video output even if inference runs at 10fps
|
||||
frame.detections.extend(self.latest_detections)
|
||||
|
||||
# 4. Run NMS to clean up overlapping boxes before display
|
||||
frame.detections = nms_by_class(frame.detections, iou_threshold=0.5)
|
||||
# This ensures smooth video output even if inference runs at lower fps
|
||||
frame.detections = self.latest_detections.copy()
|
||||
|
||||
# Ticket dispatch: Only attach to ONE frame, then clear
|
||||
# This prevents duplicate alerts in sinks like FileAlertStore
|
||||
@@ -146,6 +143,9 @@ class SmokingDetectionPipeline:
|
||||
|
||||
# --- Step 1: Broad Phase (Person Detection) ---
|
||||
people = self.person_model.predict(frame.data)
|
||||
|
||||
people = nms_by_class(people, iou_threshold=0.7)
|
||||
|
||||
detections.extend(people)
|
||||
|
||||
if not people:
|
||||
@@ -153,13 +153,13 @@ class SmokingDetectionPipeline:
|
||||
return False, detections, None
|
||||
|
||||
# --- Step 2: Narrow Phase (Cigarette Candidate) ---
|
||||
candidates = self._find_candidates(frame, people)
|
||||
candidates = self._find_candidates(frame, people, detections)
|
||||
|
||||
if not candidates:
|
||||
return True, detections, None
|
||||
|
||||
# --- Step 3: Verification (Classifier) ---
|
||||
best_hit = self._verify_candidates(frame, candidates)
|
||||
best_hit = self._verify_candidates(frame, candidates, detections)
|
||||
|
||||
ticket = None
|
||||
# --- Step 4: Action ---
|
||||
@@ -188,6 +188,9 @@ class SmokingDetectionPipeline:
|
||||
)
|
||||
detections.append(verified_det)
|
||||
|
||||
# Clean up overlapping boxes from model output
|
||||
detections = nms_by_class(detections, iou_threshold=0.5)
|
||||
|
||||
dt = time.time() - t0
|
||||
if dt > 0.1:
|
||||
logger.debug("Inference took %.3fs (Slow)", dt)
|
||||
@@ -195,9 +198,13 @@ class SmokingDetectionPipeline:
|
||||
return True, detections, ticket
|
||||
|
||||
def _find_candidates(
|
||||
self, frame: Frame, people: List[Detection]
|
||||
self, frame: Frame, people: List[Detection], detections_out: List[Detection]
|
||||
) -> List[Tuple[Detection, List[Detection], Tuple[int, int]]]:
|
||||
"""Runs cigarette detection on expanded person crops."""
|
||||
"""Runs cigarette detection on expanded person crops.
|
||||
|
||||
Args:
|
||||
detections_out: List to append candidate detections to (thread-safe output)
|
||||
"""
|
||||
candidates = []
|
||||
h_img, w_img = frame.data.shape[:2]
|
||||
margin = 0.2 # 20% expansion
|
||||
@@ -226,12 +233,13 @@ class SmokingDetectionPipeline:
|
||||
# 3. Detect
|
||||
cig_candidates = self.cigarette_model.predict(person_crop)
|
||||
|
||||
# 4. Filter Noise
|
||||
# 4. Filter Noise + NMS (model can return overlapping boxes for same cig)
|
||||
cig_candidates = [
|
||||
c
|
||||
for c in cig_candidates
|
||||
if (c.box.x2 - c.box.x1) >= 10 and (c.box.y2 - c.box.y1) >= 10
|
||||
]
|
||||
cig_candidates = nms_by_class(cig_candidates, iou_threshold=0.5)
|
||||
|
||||
if cig_candidates:
|
||||
candidates.append((person, cig_candidates, (ex1, ey1)))
|
||||
@@ -250,14 +258,18 @@ class SmokingDetectionPipeline:
|
||||
label="candidate_cig",
|
||||
metadata=cig.metadata,
|
||||
)
|
||||
frame.detections.append(global_cig)
|
||||
detections_out.append(global_cig)
|
||||
|
||||
return candidates
|
||||
|
||||
def _verify_candidates(
|
||||
self, frame: Frame, candidates: List[Tuple]
|
||||
self, frame: Frame, candidates: List[Tuple], detections_out: List[Detection]
|
||||
) -> Optional[Tuple]:
|
||||
"""Runs verification on candidate crops."""
|
||||
"""Runs verification on candidate crops.
|
||||
|
||||
Args:
|
||||
detections_out: List to append verified detections to (thread-safe output)
|
||||
"""
|
||||
confirmed_hits = []
|
||||
|
||||
for person, cigs, (ex1, ey1) in candidates:
|
||||
@@ -305,7 +317,7 @@ class SmokingDetectionPipeline:
|
||||
label="verified_smoking",
|
||||
metadata={"verifier_score": score},
|
||||
)
|
||||
frame.detections.append(verified_det)
|
||||
detections_out.append(verified_det)
|
||||
|
||||
if confirmed_hits:
|
||||
return max(confirmed_hits, key=lambda x: x[2])
|
||||
|
||||
Reference in new issue
Block a user