Skip to content

Model Inference

Use the loaded ONNX model to perform AI inference prediction on the specified device and return the model's inference results.

API Description

API Type

predictOnnxModel

Parameters

ParameterTypeRequiredDescription
onnxidstringYesModel ID returned by loadOnnxModel
deviceIdstringYesDevice ID for getting screenshot
rectarrayNoPrediction region [x1, y1, x2, y2], defaults to full screen

Return Value

Returns the model's inference results.

javascript
// Typical return format for YOLO object detection model
[
    {
        "classId": 0,
        "x": 100,
        "y": 200,
        "confidence": 0.95,
        "boundingBox": { ... }  // [x, y, width, height]
    },
    {
        "classId": 1,
        "x": 100,
        "y": 200,
        "confidence": 0.87,
        "boundingBox": { ... }
    }
]

Basic Usage

javascript
// 1. Load model
const onnxid = await apiInvoke('loadOnnxModel', {
    file: 'C:\\models\\yolov5s.onnx'
});

// 2. Perform inference
const result = await apiInvoke('predictOnnxModel', {
    onnxid: onnxid,
    deviceId: 'P72578581E07'
});

console.log('Detection results:', result);

Cooperation: try.catch@foxmail.com