Skip to content

Add Per-Class Confidence Filter workflow block#2283

Open
dcaroboflow wants to merge 2 commits intomainfrom
add-per-class-confidence-filter-block
Open

Add Per-Class Confidence Filter workflow block#2283
dcaroboflow wants to merge 2 commits intomainfrom
add-per-class-confidence-filter-block

Conversation

@dcaroboflow
Copy link
Copy Markdown

@dcaroboflow dcaroboflow commented Apr 28, 2026

Summary

Adds a new transformation block roboflow_core/per_class_confidence_filter@v1 that filters detection predictions by applying a different confidence threshold per class.

  • Keeps a detection only if its confidence is at least the threshold configured for its class
  • Classes not listed in class_thresholds fall back to a configurable default_threshold (defaults to 0.3)
  • Supports object detection, instance segmentation, and keypoint detection prediction kinds
  • Registered in core_steps/loader.py; appears as Per-Class Confidence Filter under the flow_control section in the Workflows UI

Why a new block

The existing detections_filter block applies a single confidence threshold across all classes — you can filter to a class list or set a global confidence cutoff, but you cannot say "keep person only above 0.98 and car only above 0.5" without writing extremely verbose nested StatementGroups by hand (which the UI's Configure popup does not surface). This block fills that gap with a purpose-built {class_name: threshold} input for the common per-class case.

API

```json
{
"type": "roboflow_core/per_class_confidence_filter@v1",
"name": "filter",
"predictions": "$steps.detector.predictions",
"class_thresholds": {"person": 0.98, "car": 0.5},
"default_threshold": 0.3
}
```

class_thresholds also accepts a workflow input or step output selector pointing to a dictionary.

Tests

  • Unit tests (tests/workflows/unit_tests/core_steps/transformations/test_per_class_confidence_filter.py): manifest validation, per-class threshold drops, inclusive boundary, unknown-class fallback, empty predictions, empty thresholds, batch processing
  • Integration test (tests/workflows/integration_tests/execution/test_workflow_with_per_class_confidence_filter.py): full ExecutionEngine path with synthetic detections, including default-threshold fallback and multi-image batches

All 15 tests pass locally. `make style` applied.

Test plan

  • `pytest tests/workflows/unit_tests/core_steps/transformations/test_per_class_confidence_filter.py` (12 cases)
  • `pytest tests/workflows/integration_tests/execution/test_workflow_with_per_class_confidence_filter.py` (3 cases)
  • Manually verified end-to-end via local inference server with mounted volume against YOLO-World predictions on a real image; filter drops/keeps detections per-class as configured
  • Verified block registers in /workflows/blocks/describe with correct UI metadata (name, section, icon)

Adds a new transformation block roboflow_core/per_class_confidence_filter@v1
that filters detection predictions using a different confidence threshold
per class. Detections are kept only if their confidence is at least the
threshold configured for their class, with a configurable default_threshold
fallback for classes that are not listed.

The existing detections_filter block can express this via its query language,
but requires a verbose StatementGroup/BinaryStatement configuration. This
block exposes a simple {"class_name": threshold} dictionary for the common
per-class case.

Supports object detection, instance segmentation, and keypoint detection
prediction kinds. Includes a unit test suite covering manifest validation,
boundary conditions, unknown-class fallback, empty inputs, and batch
processing, plus an integration test exercising the full ExecutionEngine
path with synthetic detections.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 28, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants