Skip to main content

rectiou: vectorized 2d rectangle intersection with pytorch

Project description

rectiou

Rectiou is a pytorch implementation of the intersection over union (IoU) between two rotated rectangles.

Supports:

  • ✅ Works with rotated rectangles: can handle rectangles with any angle.
  • ✅ Batched computation: No for loops, if statements, or other control flow. Can have as many batch dimensions as you want.
  • ✅ Fast: faster than OpenCV's implementation.
  • ✅ Differentiable: Can be used in a pytorch model and backpropagated through.
  • ✅ GPU: can be run on the GPU.
  • ✅ No weird stuff: everything is implemented in plain pytorch, no weird custom CUDA kernels or anything like that.

Example

Usage is simple:

import torch
import rectiou

# Rectangles: [x, y, w, h, radians]
rect_a = torch.tensor([0.0, 0.0, 1.0, 1.0, 0.0])
rect_b = torch.tensor([0.2, 0.1, 1.1, 0.8, torch.pi / 4])

# Intersection over union
iou = rectiou.compute_iou(rect_a, rect_b)

Installation

pip install rectiou

To test that everything is working correctly, run:

pip install rectiou[tests]
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rectiou-0.0.1.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

rectiou-0.0.1-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page