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
predictOnnxModelParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| onnxid | string | Yes | Model ID returned by loadOnnxModel |
| deviceId | string | Yes | Device ID for getting screenshot |
| rect | array | No | Prediction 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);