Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt at sparse implementation #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

redhog
Copy link

@redhog redhog commented Nov 16, 2022

Hi!

When working with large numbers of bboxes (at least outside of the neural network domain), it is useful to use sparse matrixes (as most bboxes won't overlap).

I have mashed together a some very simple support for that here, mostly as a discussion starter. Would you be ok with including something along these lines?

If so, I'd be happy to discuss how to make a better PR (for now, I basically included two copies of the code, one sparse and one dense, which is not optimal, but at least does not slow down either implementation).

Usage example:

>>> ov = cython_bbox.bbox_overlaps(shapes.bounds.values, shapes.bounds.values, True)
>>> print(type(ov), ov.size, (ov > 0).sum(), ov.shape[0]*ov.shape[1])
<class 'scipy.sparse._arrays.dok_array'> 27906 27906 6574096

>>> ov = cython_bbox.bbox_overlaps(shapes.bounds.values, shapes.bounds.values)
>>> print(type(ov), ov.size, (ov > 0).sum(), ov.shape[0]*ov.shape[1])
<class 'numpy.ndarray'> 6574096 27906 6574096

Best regards,
Egil

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