Skip to content

Conversation

@AnonymDevOSS
Copy link

@AnonymDevOSS AnonymDevOSS commented Oct 27, 2025

Description

I focused on improving the performance of the IoU calculation between bounding boxes.

This change adds a new function box_iou_batch_alt, which performs the same computation as box_iou_batch but runs faster and uses less memory.

The optimization uses in-place NumPy operations and avoids creating temporary arrays.
Results are identical to the original implementation within a small numerical tolerance.

No new dependencies were added.

Type of change

Performance improvement (non-breaking change)

How has this change been tested, please provide a testcase or example of how you tested the change?

I compared the outputs of both functions (box_iou_batch and box_iou_batch_alt) using random test boxes.
A simple pytest test checks that the results are equal within rtol=1e-6 and atol=1e-6.
Both functions return the same values for IoU and IoS modes.
Benchmarks show that the new version is around 2–5× faster on typical box sizes.

I also add a benchmark.

(.venv) wednesday:benchmark rafelbennasar$ python benchmark_iou.py 
Benchmarking 2 functions on sizes=[(512, 1024)], 5 runs × 5 iterations each

- box_iou_batch  (512×1024)
[benchmark_iou.py](https://github.com/user-attachments/files/23167441/benchmark_iou.py)

  Run 01:   0.241 s
  Run 02:   0.232 s
  Run 03:   0.522 s
  Run 04:   0.246 s
  Run 05:   0.207 s
  Average:   0.290 s

- box_iou_batch_alt  (512×1024)
  Run 01:   0.060 s
  Run 02:   0.064 s
  Run 03:   0.066 s
  Run 04:   0.065 s
  Run 05:   0.066 s
  Average:   0.064 s


= Summary (5 runs × 5 iterations each):
box_iou_batch_alt           avg=  0.064s  stdev= 0.002s  min= 0.060s  max= 0.066s
box_iou_batch               avg=  0.290s  stdev= 0.131s  min= 0.207s  max= 0.522s


@CLAassistant
Copy link

CLAassistant commented Oct 27, 2025

CLA assistant check
All committers have signed the CLA.

@SkalskiP
Copy link
Collaborator

Hi @AnonymDevOSS 👋🏻 thanks a lot for the contribution!

Please accept the CLA license so we can move forward.

@AnonymDevOSS
Copy link
Author

I’m a little confused because I believe I’ve already accepted the license agreement.

image
@SkalskiP
Copy link
Collaborator

Looks like you used different account to commit the code.

Screenshot 2025-10-28 at 13 05 08
without creating intermediary (N, M, 2) arrays.
@AnonymDevOSS AnonymDevOSS force-pushed the feat/speed-up-box-iou-batch branch from 6aa194f to 35ff87b Compare October 28, 2025 12:51
@AnonymDevOSS
Copy link
Author

Oops. Thanks for the heads up! Fixed.

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

Labels

None yet

3 participants