Bundle 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.
FaceSession
Face recognition session wrapping an SCRFD detector and an ArcFace recognizer. Detect() returns bounding boxes and landmarks; Recognize() additionally extracts 512-dim embeddings for identity comparison via Compare().
Example
session := FaceSession->New("det_10g.onnx", "w600k_r50.onnx");
r1 := session->Recognize(image1_bytes, 0.5);
r2 := session->Recognize(image2_bytes, 0.5);
if(r1->GetSize() > 0 & r2->GetSize() > 0) {
faces1 := r1->GetResults();
faces2 := r2->GetResults();
sim := FaceSession->Compare(faces1[0]->GetEmbedding(), faces2[0]->GetEmbedding());
"Similarity: {$sim}"->PrintLine(); # >0.35 = same person
};
session->Close();Operations
Compare # function
Compute cosine similarity between two L2-normalised ArcFace embeddings. Returns a value in [-1, 1]; typically >0.35 indicates the same person.
function : Compare(emb1:Float[], emb2:Float[]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| emb1 | Float | first embedding (512 floats) |
| emb2 | Float | second embedding (512 floats) |
Return
| Type | Description |
|---|---|
| Float | cosine similarity score |
Example
r1 := session->Recognize(image1, 0.5);
r2 := session->Recognize(image2, 0.5);
sim := FaceSession->Compare(r1->GetResults()[0]->GetEmbedding(), r2->GetResults()[0]->GetEmbedding());
"Same person? {$sim > 0.35}"->PrintLine();Detect #
Detect all faces in an image.
method : public : Detect(image:Byte[], conf_threshold:Float) ~ FaceDetectionResultParameters
| Name | Type | Description |
|---|---|---|
| image | Byte | raw image bytes (JPEG/PNG) |
| conf_threshold | Float | detection confidence threshold [0, 1] |
Return
| Type | Description |
|---|---|
| FaceDetectionResult | array of FaceDetection results |
Example
session := FaceSession->New("det_10g.onnx");
image := FileReader->ReadBinaryFile("group.jpg");
result := session->Detect(image, 0.5);
"Faces found: {$result->GetSize()}"->PrintLine();
session->Close();New # constructor
Constructor - detection only (no recognizer loaded).
New(det_model:String)Parameters
| Name | Type | Description |
|---|---|---|
| det_model | String | path to SCRFD detector ONNX model (e.g. det_10g.onnx) |
New # constructor
Constructor - detection + recognition.
New(det_model:String, rec_model:String)Parameters
| Name | Type | Description |
|---|---|---|
| det_model | String | path to SCRFD detector ONNX model (e.g. det_10g.onnx) |
| rec_model | String | path to ArcFace recognizer ONNX model (e.g. w600k_r50.onnx) |
New # constructor
Constructor with configuration options.
New(det_model:String, rec_model:String, config:Map<String,String>)Parameters
| Name | Type | Description |
|---|---|---|
| det_model | String | path to SCRFD detector ONNX model |
| rec_model | String | path to ArcFace recognizer ONNX model |
| config | Map<String,String> | key/value execution-provider options (e.g. "ep"->"cpu") |
Recognize #
Detect faces and extract ArcFace embeddings for each. Requires the recognizer model to have been loaded.
method : public : Recognize(image:Byte[], conf_threshold:Float) ~ FaceRecognitionResultParameters
| Name | Type | Description |
|---|---|---|
| image | Byte | raw image bytes (JPEG/PNG) |
| conf_threshold | Float | detection confidence threshold [0, 1] |
Return
| Type | Description |
|---|---|
| FaceRecognitionResult | array of FaceResult (detection + 512-dim embedding) |
Example
session := FaceSession->New("det_10g.onnx", "w600k_r50.onnx");
image := FileReader->ReadBinaryFile("portrait.jpg");
result := session->Recognize(image, 0.5);
each(face in result->GetResults()) {
"Face score: {$face->GetDetection()->GetScore()}"->PrintLine();
};
session->Close();