Skip to content

Smirkey/powerboxes

Repository files navigation

CI Coverage Crates.io pypi versions

PowerBoxes

Powerboxes is a package containing utility functions for transforming bounding boxes and computing metrics. It is implemented in both Python and Rust. It shows a significant speedup over the equivalent numpy implementations in Python, or other libraries such as shapely or torchvision.

Checkout out the documentation !

🦀 Rust documentation

🐍 Python documentation

Installation

Python

pip install powerboxes

Rust

cargo add powerboxesrs

Python Usage

import powerboxes as pb
import numpy as np

# Create a bounding box
box = np.array([[0, 0, 1, 1]])

# Compute the area of the box
area = pb.box_areas(box)

# Compute the intersection of the box with itself
intersection = pb.iou_distance(box, box)

Use it in Rust

Here is a simple example:

use ndarray::array;
use powerboxesrs::boxes::box_areas;
let boxes = array![[1., 2., 3., 4.], [0., 0., 10., 10.]];
let areas = box_areas(&boxes);
assert_eq!(areas, array![4., 100.]);

Benchmarks

Some benchmarks of powerboxes against various open source alternatives, not all functions are benchmarked. Notice that we use log scales, all differences are major ! Benchmarks can be found in this google colab notebook

Box area

Here it's torchvision vs powerboxes vs numpy

Box area

Box convert

Here it's torchvision vs powerboxes

Box convert

Box IoU matrix

Torchvision vs numpy vs powerboxes

Box IoU

NMS

Torchvision vs powerboxes vs lsnms vs numpy

Large image (10000x10000 pixels)

Box NMS

Normal image (1000x1000 pixels)

Box NMS