From Prediction to Production: Inference, Export, and Deployment

RF-DETR’s trained checkpoint becomes a working system only when the bytes entering the model, the tensors leaving it, and the runtime executing them preserve the same meaning. The important question is therefore not which file format is available, but which assumptions cross each boundary: normalization, resize geometry, score activation, output ordering, class layout, batch shape, and hardware specialization. Following that contract helps the reader choose between Python inference, exported graphs, target-specific engines, and Roboflow deployment without mistaking a successful conversion for a validated production result.

predict() is a semantic contract

The public RF-DETR inference path accepts a single image or a list of images. Inputs can be file paths or URLs, PIL images, NumPy arrays, or tensors. That flexibility belongs at the boundary; once an image enters the model, it must become a tensor with the expected channel layout and numerical range. Tensor inputs are expected to be channel-first and already scaled to the required range, while ordinary image inputs are converted and normalized by the library.

The resize operation is part of the contract rather than a cosmetic preparation step. RF-DETR’s documented path uses antialias-free bilinear resizing, and the inference and export helpers are aligned to that convention. A different interpolation filter can change pixel values enough to change scores, especially when a deployment team compares an exported runtime with a Python reference. The same model weights can consequently appear to have different quality when the actual difference is preprocessing.

The spatial shape has a structural constraint as well. The height and width used for prediction must be divisible by the selected patch size multiplied by the number of attention windows. That rule comes from the windowed backbone and the reconstruction of spatial features; it is not an arbitrary API preference. If the reader changes the inference shape, they are changing the geometry assumed by the backbone and must validate the resulting model at that shape.

After the forward pass, RF-DETR’s postprocessor converts normalized center-format boxes into pixel-space corner boxes and clamps them to the image bounds. It applies sigmoid scores, flattens query/class candidates, and selects the highest-scoring pairs globally. Detection and segmentation models return Supervision Detections; keypoint models return KeyPoints with task-specific coordinates and uncertainty-related fields. Class names are resolved differently for pretrained COCO layouts and fine-tuned class lists, so a downstream application should use the names carried by the checkpoint rather than infer them from a numeric index without checking the layout.

That last point is easy to underestimate. In a normal application, “class 3” sounds like a stable identifier. In RF-DETR, its meaning can depend on whether the checkpoint retains sparse COCO category IDs, uses contiguous fine-tuned IDs, or has a legacy background arrangement. The exported tensor width does not tell a consumer which slot is background. A decoder that assumes the final slot in every checkpoint can produce plausible boxes with wrong labels. Semantic validation must therefore include class mapping, not only tensor shape.

Optimization introduces another boundary. The inference API can compile a model for a fixed batch size and resolution, with a one-time setup cost that may reduce steady-state latency. It can also optimize in place and cast to a lower-precision floating-point type for a memory-constrained, inference-only process.