SAHI 0.12.2 is out: postprocessing no longer allocates a quadratic matrix #1396
Pinned
onuralpszr
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
SAHI
0.12.2is out.pip install -U sahiIt fixes out-of-memory failures and severe slowdowns when postprocessing large detection counts.
What broke
0.11used a shapely STRtree and only compared boxes the index reported as nearby.0.12replaced it with a denseN x Noverlap matrix, which isO(N^2)in time and memory whatever the layout.nmm_from_matrixadded five moreN x Nbool arrays, and the TorchVision backend had no size guard, so it built sevenN x Ntensors on the GPU and ran out of memory first. For the 33337 boxes in #1374 that is33337^2 * 4 = 4.14 GiBin a single allocation.The fix
The greedy loops only ever use
matrix >= match_threshold, never the metric values. So the thresholded adjacency is now built directly from the pairs an STRtree reports as intersecting, stored as CSR. The dense matrix is never allocated. shapely was already a dependency.NumPy, TorchVision and Numba all route large inputs there. Inputs below 2000 boxes stay on the dense path, where it is faster, and so does any non-positive threshold, since that matches disjoint pairs the intersection prefilter never enumerates.
Numbers
33337 boxes,
IOSmetric, threshold0.3, on an i7-13850HX with an RTX 4000 Ada Laptop (12 GB). Outputs are identical before and after: 6571 predictions forgreedy_nmm, 4639 fornmm.CPU:
CUDA:
Worth knowing
Above the 2000-box cutoff the TorchVision backend delegates to the NumPy sparse functions, so it no longer uses the GPU for those inputs. It is far faster than the dense GPU path was, but the backend name no longer implies GPU execution there.
The dense TorchVision path computed the metric in float32 while the sparse path uses the input dtype, so a pair sitting exactly on the threshold could round differently between them. Nothing in the test suite hit this.
Also in 0.12.2
RF-DETR local models loadable by class name (#1394), an MMDetection
RepeatDatasetfix inhas_mask(#1387), enforced dependency and minimum-version checks inimport_utils(#1377), OpenCV distributions kept on one version (#1393), and completed Chinese documentation (#1371).Full notes: https://github.com/obss/sahi/releases/tag/0.12.2
If you hit the OOM or the slowdown before, please upgrade and let us know how it goes.
All reactions