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, positive sides and nonzero direction vectors. Relative to the largest side in a pair, 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. 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.0

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.0
File Interpreter ABI Platform Actions
obb_loss-0.12.0-py3-none-any.whl Python 3 none any Details for obb_loss-0.12.0-py3-none-any.whl

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

Download URL obb_loss-0.12.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
163b4c11fe97be0c5e7c4afefe2ac895e15e9d15f062c34d0c321256ecee2e72
BLAKE2b-256 checksum
How to use checksums
8b53383f3c1ded02da8acfcf0e3d9f999875c5caf144588117c1c8c9338e7425
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.0

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