Skip to content

perf(vision): accelerate class-aware batched NMS - #36

Merged
rsasaki0109 merged 1 commit into
mainfrom
agent/batched-nms-opencv-performance
Jul 15, 2026
Merged

rsasaki0109 merged 1 commit into
mainfrom
agent/batched-nms-opencv-performance

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

What changed

  • bucket accepted batched-NMS indices by class so candidates never scan kept boxes from unrelated classes
  • expose a one-call spatialrust.batched_nms NumPy API with contiguous borrowing and non-contiguous fallbacks
  • add Rust reference-parity tests, Python binding contracts, and native Criterion coverage
  • add an exact-index OpenCV dnn.NMSBoxesBatched comparison harness and register it in the benchmark manifest
  • publish the measured outcome in README, ROADMAP, GitHub Pages, and a dated receipt

Why

Class-aware NMS is a canonical object-detection post-processing step. The old Rust core preserved the correct semantics but scanned every globally kept detection and discarded unrelated classes inside the hot loop. Keeping a vector per class removes those comparisons without changing the global score-ordered result.

Measured impact

Windows 11, 6-core/12-thread Intel CPU, CPython 3.12.10, OpenCV 4.10, OpenCL off; seeded interleaved Python API medians:

Profile OpenCV SpatialRust Speedup
1,000 candidates / 20 classes 3.5377 ms 0.1341 ms 26.38×
8,400 candidates / 80 classes 211.7618 ms 2.1776 ms 97.25×

Both profiles return exactly the same ordered kept indices. Another 32 randomized OpenCV parity cases also passed locally.

Validation

  • cargo test -p spatialrust-vision --features detection
  • cargo clippy -p spatialrust-vision --all-targets --features detection -- -D warnings
  • cargo clippy --manifest-path crates/spatialrust-py/Cargo.toml --all-targets -- -D warnings
  • changed Rust files pass rustfmt --check
  • full Python binding suite passes (one existing skip)
  • OpenCV report-contract tests and generated report validation pass
  • native Criterion: about 98.3 µs at 1,000 and 2.42 ms at 8,400 on a separately seeded 80-class workload
  • cargo doc -p spatialrust-vision --features detection --no-deps
  • git diff --check

@rsasaki0109
rsasaki0109 marked this pull request as ready for review July 15, 2026 13:34
@rsasaki0109
rsasaki0109 merged commit dff3781 into main Jul 15, 2026
86 of 92 checks passed
@rsasaki0109
rsasaki0109 deleted the agent/batched-nms-opencv-performance branch July 15, 2026 13:37
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.

1 participant