ONNX Runtime inference library for running pre-trained models. Supports object detection (YOLO), image classification (ResNet), segmentation (DeepLab), pose estimation (OpenPose), face recognition, and Phi-3 text generation. Compile with -lib onnx.
YoloSession
YOLO inference session for object detection (v8 and above). Supports YOLO11/YOLO12 with fused head, letterbox preprocessing, and automatic FP16/FP32 input handling.
Example
labels := ["person", "bicycle", "car"];
session := YoloSession->New("yolo11n.onnx");
result := session->Inference(image_bytes, 640, 640, 0.5, labels);
each(cls in result->GetClassifications()) {
"{cls->GetName()}: {cls->GetConfidence()}"->PrintLine();
};
session->Close();Operations
Inference #
Yolo image inference, support for models v8 and above
method : public : Inference(image:Byte[], height:Int, conf_threshold:Float, labels:String[]) ~ API.Onnx.YoloResultParameters
| Name | Type | Description |
|---|---|---|
| image | Byte | width width |
| height | Int | image height |
| conf_threshold | Float | confidence threshold |
| labels | String | classification labels |
Example
labels := ["person", "car", "dog"];
session := YoloSession->New("yolo11n.onnx");
image := FileReader->ReadBinaryFile("photo.jpg");
result := session->Inference(image, 640, 640, 0.5, labels);
each(cls in result->GetClassifications()) {
"{$cls->GetName()}: {$cls->GetConfidence()}"->PrintLine();
};
session->Close();IsOpen #
Whether the model loaded. A session that failed to open is not an error at construction -- the constructor returns an object either way, and the reason was written to stderr while it happened. Test this before inferring: a closed session returns Nil from every inference method, which is otherwise indistinguishable from a model that found nothing.
method : public : IsOpen() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when the model is loaded and inference can run |