Skip to main content

obb_loss

Pure PyTorch oriented-box and quality-classification losses. Python 3.11+; development defaults to Python 3.12.

import torch
import obb_loss as obb

preds = torch.tensor([[0., 0., 2., 1., 1., 0.]], requires_grad=True)
targets = torch.tensor([[0.1, 0., 2., 1., 1., 0.]])
match obb.stable_probiou_loss(preds, targets):
    case obb.Ok(values):
        values.mean().backward()
    case obb.Err(error):
        print(error)

The public functions are stable_probiou_loss, stable_probiou, box_l1_loss, varifocal_loss, and quality_focal_loss. Each returns Ok(tensor) or a typed Err(InputError) for incompatible shapes, non-floating dtypes, or device mismatch. Validation reads metadata only. Numerical input values and scalar options are the caller's responsibility. There are no separate checked APIs.

Boxes use (cx, cy, width, height, cos(theta), sin(theta)). ProbIoU supports broadcastable leading dimensions. L1 accepts aligned [pairs, 6] tensors and sums absolute errors over the first four coordinates. Classification losses accept aligned [items, classes] logits and caller-supplied quality targets. Quality must be in [0, 1]; zero denotes a negative class.

All losses return unreduced float64 tensors, disable autocast locally, preserve autograd, and borrow inputs without mutation. Reduction, weighting, matching, and detector orchestration belong to the caller. Empty inputs produce empty outputs; choose an explicit policy before applying a mean.

ProbIoU requires finite boxes and nonnegative sides. Nonzero direction vectors are normalized internally, so (1, 1) and (0.5, 0.5) represent the same angle. If either box has a zero side or a (0, 0) direction, its pair receives loss 1 and similarity 0, with zero ProbIoU gradients for both boxes. Safe geometry is substituted before computation to avoid NaN derivatives. An additional L1 loss can still supply size gradients, unless the decoding derivative is zero.

For nondegenerate pairs, relative to the largest side, sides must be at least 1e-30 and center offsets at most 1e30. The implementation uses positive covariance residuals, common scale normalization, log1p, and expm1 to avoid cancellation. Translation residuals saturate for distant pairs. Coincident boxes use a zero subgradient. Float64 internal computation cannot prevent overflow when gradients are cast back into low-precision leaf tensors. Use FP32 box-head projection and decoding for small boxes: FP16 cannot represent some correct gradients even when the loss is finite. These numerical choices are explained next to the implementation.

References:

Run uv sync and just check for strict Ruff, native Pyrefly shape checking, and pytest. Configurations are separate: ruff.toml, pyrefly.toml, and pytest.ini. The type-check runner provisions a locked Python 3.12 shape-checking environment when the runtime is Python 3.11.

Tests cover metadata contracts, independent paper-equation oracles, gradients, compilation, mixed precision, and seeded numerical stress simulations. CPU tests always run; CUDA cases skip when CUDA is unavailable. Simulations provide evidence for their tested domains, rather than a proof for every floating-point input.

Metadata

Release files for obb-loss 0.12.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for obb-loss 0.12.1
File Interpreter ABI Platform Actions
obb_loss-0.12.1-py3-none-any.whl Python 3 none any Details for obb_loss-0.12.1-py3-none-any.whl

Release files / obb_loss-0.12.1-py3-none-any.whl

Download URL obb_loss-0.12.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6413a082319f7250933fb9e0420af1bc1db72ed453b9dd3dc0790261cb31ba7
BLAKE2b-256 checksum
How to use checksums
6c84435620e2ba216acd40c6848054fecac88c3159a9a15bbda11468521a5886
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for obb-loss 0.12.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page