Skip to main content

A Python library for Random Set Neural Networks with uncertainty estimation

Project description

R3ALAI

Python SDK for Random Set Neural Networks (RSNN): uncertainty estimation, conformal prediction, and active learning. Built to add RSNN benefits (sample efficiency, robustness, reliability) to ML workflows.

Install

  • Base: pip install r3alai
  • With vision backbones: pip install 'r3alai[vision]'
  • With YOLO: pip install 'r3alai[yolo]'

Requires Python 3.8+ and PyTorch.

What it provides

  • r3alai.models: RSNNClassifier — RSNN head on a backbone (torchvision or custom nn.Module).
  • r3alai.conformal: ConformalPredictor — confidence sets with distribution-free coverage after calibration.
  • r3alai.active_learning: ActiveLearner — entropy/credal querying and simple disagreement mode.
  • r3alai.utils: RSNNYOLOWrapper, YOLOFeatureExtractor — plug RSNN uncertainty into YOLOv8.

How to use (high-level)

  1. Create an RSNN model
  • Pick a backbone: "resnet50", "mobilenet_v2", "efficientnet_b0", or use a custom backbone.
  • Set n_classes (one-hot labels expected). Optional alpha/beta regularization.
  1. Train
  • Call fit(X, y, ...) with tensors/ndarrays; early stopping and LR scheduling are included.
  1. Predict with uncertainty
  • Call predict(..., return_uncertainty=True) to get predictions, pignistic entropy, and credal width.

Conformal prediction

  1. Wrap a trained RSNN with ConformalPredictor(confidence_level=0.9/0.95).
  2. Calibrate on a held-out split (features and one-hot labels).
  3. Use predict for confidence sets; get_coverage to measure empirical coverage.

Active learning

  1. Construct ActiveLearner(model, uncertainty_measure="entropy"|"credal").
  2. Provide an unlabeled pool to query to select samples and indices for annotation.

YOLO integration (optional)

  1. Install extras: r3alai[yolo].
  2. Initialize RSNNYOLOWrapper(yolo_model_path, n_classes).
  3. Train with your DataLoaders; optionally calibrate conformal and then predict with uncertainty or confidence sets.

Custom backbones and frameworks

  • Custom nn.Module: set base_model="custom", assign your module to rsnn_model.base_model, then call set_belief_layer(feature_dim).
  • Hugging Face models: adapt outputs to a 512-dim feature vector and connect as a custom backbone.

Tips

  • Keep a small calibration split to enable conformal coverage.
  • Start active learning with entropy querying; try disagreement for harder pools.
  • For detection, first freeze the YOLO backbone and train only the RSNN head.

Support

  • See docstrings on RSNNClassifier, ConformalPredictor, ActiveLearner, and RSNNYOLOWrapper.
  • Report issues and requests on GitHub Issues.

License

MIT

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

r3alai-0.1.3.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

r3alai-0.1.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file r3alai-0.1.3.tar.gz.

File metadata

  • Download URL: r3alai-0.1.3.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for r3alai-0.1.3.tar.gz
Algorithm Hash digest
SHA256 63a27a58cc2ab554259b751e5722152ff3dcc839d7c037a3c084e6e9adb8ff4d
MD5 ea645c341faaf560e51d17e917ba1206
BLAKE2b-256 564ae78230b865599cb6ab62c8dfb89f2165ffab6ce3db248361cae167e56196

See more details on using hashes here.

Provenance

The following attestation bundles were made for r3alai-0.1.3.tar.gz:

Publisher: publish.yml on R3AL-AI/package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file r3alai-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: r3alai-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for r3alai-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a5755dcc7457a85c85c30ed27ce09c4e29af250e1976bfec1d5caa60e5df9d68
MD5 2fab9f6248e3dfc6e4071427ec9a6cf1
BLAKE2b-256 a210227d24f8d7091c33524eef340c5356be4eae88cc7c33f6fbd06dd27e0137

See more details on using hashes here.

Provenance

The following attestation bundles were made for r3alai-0.1.3-py3-none-any.whl:

Publisher: publish.yml on R3AL-AI/package

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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