- Move test scripts to tests/ directory for better organization - Add improved YOLOv5 postprocessing with reference implementation - Update gitignore to exclude *.mflow files and include main.spec - Add debug capabilities and coordinate scaling improvements - Enhance multi-series support with proper validation - Add AGENTS.md documentation and example utilities 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
26 lines
808 B
Python
26 lines
808 B
Python
|
|
def emergency_filter_detections(boxes, max_total=50, max_per_class=10):
|
|
"""緊急過濾檢測結果"""
|
|
if len(boxes) <= max_total:
|
|
return boxes
|
|
|
|
# 按類別分組
|
|
from collections import defaultdict
|
|
class_groups = defaultdict(list)
|
|
for box in boxes:
|
|
class_groups[box.class_name].append(box)
|
|
|
|
# 每類保留最高分數的檢測
|
|
filtered = []
|
|
for class_name, class_boxes in class_groups.items():
|
|
class_boxes.sort(key=lambda x: x.score, reverse=True)
|
|
keep_count = min(len(class_boxes), max_per_class)
|
|
filtered.extend(class_boxes[:keep_count])
|
|
|
|
# 總數限制
|
|
if len(filtered) > max_total:
|
|
filtered.sort(key=lambda x: x.score, reverse=True)
|
|
filtered = filtered[:max_total]
|
|
|
|
return filtered
|