Skip to content

Export and Deploy Models ​

SUMMARY

Export trained Iris models into inference-ready artifacts and run predictions using the shared Model interface. RF-DETR exports to ONNX, while SAM3-LoRA produces an Iris .pt bundle. Both return a common Prediction structure that can be used directly or visualized in Rerun.

Export and Deployment Workflow ​

Iris provides a consistent workflow for exporting, loading, and running inference across supported model architectures. Configure the deployment, export a trained checkpoint, load the resulting artifact, and run predictions on new images.

Configure Deployment ​

Define the model artifact location and select the model architecture before initializing the deployment interface.

Model Configuration ​

python
from pathlib import Path

model_path = Path("artifacts/model.pt")
model_name = "sam3-lora"
ModelModel nameArtifact
RF-DETRrfdetr.onnx
SAM3-LoRAsam3-lora.pt

Post-processing Configuration ​

Post-processing controls confidence filtering, maximum detections, and model-specific prediction behavior.

RF-DETR ​

python
from telekinesis.iris.deploy import RFDETRPostprocessConfig

postprocess = RFDETRPostprocessConfig(
    confidence_threshold=0.4,
    max_detections=100,
)

SAM3-LoRA ​

python
from telekinesis.iris.deploy import SAM3PostprocessConfig

postprocess = SAM3PostprocessConfig(
    confidence_threshold=0.5,
    max_detections=100,
    per_prompt_nms_threshold=0.5,
    prompt_conflict_policy="best_prompt",
    cross_prompt_iou_threshold=0.8,
)

SAM3-LoRA supports two prompt-conflict policies:

  • multi_label: Retains overlapping detections assigned to different prompts.
  • best_prompt: Resolves overlapping predictions to the strongest result when overlap exceeds cross_prompt_iou_threshold.

Deployment Configuration

See Configuration for all available deployment and post-processing settings.

Export Model ​

Export the trained model using the shared Trainer or directly from an existing checkpoint.

Export from Trainer ​

After completing training, export the selected checkpoint:

python
artifact_path = trainer.export(
    artifact_name="model",
    from_best=True,
)

By default, the artifact is saved in the training output directory. Specify output_dir to use a different destination.

Export an Existing Checkpoint ​

Alternatively, export a previously saved checkpoint without restarting training:

python
from telekinesis.iris.export import export_model

artifact_path = export_model(
    checkpoint_path="results/training/best.pt",
    output_dir="artifacts",
    artifact_name="model",
)

Iris identifies the model architecture from the checkpoint metadata. For legacy checkpoints without this information, explicitly provide model_name.

ModelExport formatOutput
RF-DETRONNXmodel.onnx
SAM3-LoRAIris bundlemodel.pt

RF-DETR additionally supports resolution, dynamic_batch, and opset_version export settings.

Load Model ​

Load the exported artifact through the shared Model deployment interface.

python
from telekinesis.iris.deploy import Model

model = Model(
    model_path=artifact_path,
    model_name=model_name,
    postprocess=postprocess,
)

The deployment interface initializes the corresponding runtime and applies the selected post-processing configuration.

Runtime Selection ​

ModelRuntimeConfiguration
RF-DETRONNX Runtimeproviders
SAM3-LoRAPyTorchdevice

Optional loading arguments include class_names, providers, device, and input_size. Pass only the options supported by the runtime selected for the exported artifact.

Runtime Configuration

Iris can infer the model architecture from the artifact extension. Explicitly provide model_name when required. Dynamically exported ONNX models also require input_size=(height, width).

Run Inference ​

Both model families expose the same predict() method.

python
prediction = model.predict("images/test.jpg")

Image Inputs ​

predict() accepts an image path or an HWC NumPy array. Arrays are interpreted as RGB by default. For images loaded through OpenCV, specify the BGR color format:

python
import cv2

image = cv2.imread("images/test.jpg")

prediction = model.predict(
    image,
    array_color_format="bgr",
)

Text Prompts (SAM3-LoRA) ​

SAM3-LoRA uses the category prompts embedded in the exported model bundle by default. You can override them for an individual prediction:

python
prediction = model.predict(
    "images/test.jpg",
    prompts=[
        "green circle",
        "red triangle",
        "blue square",
    ],
)

Each text prompt is evaluated against the input image. The configured post-processing policy determines how overlapping predictions are handled.

Access and Visualize Predictions ​

Iris returns a unified Prediction structure.

Access Prediction Results ​

python
print(prediction.boxes)
print(prediction.scores)
print(prediction.class_ids)
print(prediction.class_names)
print(prediction.masks)
AttributeDescription
boxesBounding boxes in absolute XYXY pixel coordinates
scoresConfidence scores for each prediction
class_idsPredicted class identifiers
class_namesOptional class labels
masksInstance segmentation masks, when available

Detection-only models return None for masks.

Visualize in Rerun ​

Predictions can be visualized alongside their corresponding input image using Rerun.

python
import cv2
import numpy as np
import rerun as rr

image = cv2.imread("images/test.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

rr.init("iris_inference", spawn=True)
rr.log("inference/image", rr.Image(image))

if len(prediction):
    labels = [
        f"{name} {score:.2f}"
        for name, score in zip(
            prediction.class_names
            or map(str, prediction.class_ids),
            prediction.scores,
            strict=True,
        )
    ]

    rr.log(
        "inference/image/detections",
        rr.Boxes2D(
            mins=prediction.boxes[:, :2],
            sizes=prediction.boxes[:, 2:] - prediction.boxes[:, :2],
            labels=labels,
        ),
    )

if prediction.masks is not None and len(prediction):
    segmentation = np.zeros(
        image.shape[:2],
        dtype=np.uint16,
    )

    # Higher-confidence instances take precedence.
    for mask, class_id in zip(
        prediction.masks[::-1],
        prediction.class_ids[::-1],
        strict=True,
    ):
        segmentation[mask] = int(class_id)

    rr.log(
        "inference/image/segmentation",
        rr.SegmentationImage(segmentation),
    )

Export Reference ​

export_model() Options ​

OptionDefaultDescription
checkpoint_pathrequiredTrainer checkpoint to export
output_dirrequiredArtifact destination directory
model_namecheckpoint metadataPublic model name for legacy checkpoints
resolutionNoneRF-DETR input resolution override
artifact_namecheckpoint stemOutput filename with or without its extension
dynamic_batchFalseEnables dynamic RF-DETR ONNX batch size
opset_version17RF-DETR ONNX operator-set version
verboseFalsePrints the exported ONNX graph

Methods ​

MethodReturnsDescription
export_model(...)PathExports RF-DETR to ONNX or SAM3-LoRA to an Iris .pt bundle
trainer.export(output_dir=None, artifact_name="model", from_best=True)PathExports the best or latest checkpoint from a training run

Deployment Reference ​

Model Options ​

OptionDefaultDescription
model_pathrequiredRF-DETR ONNX artifact or SAM3-LoRA Iris bundle
model_nameNoneExplicit public model name; otherwise inferred from the extension
class_namesNoneCategory-name mapping or SAM3 prompt sequence
postprocessNoneRFDETRPostprocessConfig, SAM3PostprocessConfig, or shared configuration
num_selectNoneDeprecated maximum-detection shorthand
background_class_id0RF-DETR class slot excluded from predictions
providersNoneOrdered ONNX Runtime providers
input_sizeNoneSpatial size required by dynamic RF-DETR ONNX models
array_color_format"rgb"Color order for NumPy inputs: "rgb" or "bgr"
deviceNonePyTorch device used for SAM3-LoRA inference

Methods ​

MethodReturnsDescription
predict(image, confidence_threshold=None, prompts=None)PredictionRuns inference with an optional confidence override and SAM3 prompts
model(image)PredictionCalls predict() with configured defaults
len(prediction)intReturns the number of predicted instances

Next Steps ​