Skip to content

加载明文模型 - YoloLoadModelEx

函数简介

从磁盘加载明文模型(ONNX / TensorRT Engine / NCNN)。

接口名称

YoloLoadModelEx

DLL 调用

long YoloLoadModelEx(long ola, string modelPath, string ncnnParamPath, string namesLabel, int modelType, int inferenceType, int inferenceDevice);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
modelPath字符串主模型路径:ONNX/Engine 单文件;NCNN 为 .bin。
ncnnParamPath字符串NCNN 的 .param 路径;非 NCNN 传空字符串。
namesLabel字符串类别名称:可选。支持 labels 文件路径、内联 | 分隔(如 人|车|狗)或多行文本;编码自动识别 ASCII/UTF-8/GBK/UTF-16 BOM。详见 类别名称表说明
modelType整数型模型后端类型,见下表。
inferenceType整数型推理任务类型,见下表。
inferenceDevice整数型inferenceDevice-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
handle := ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let handle = ola.yolo_load_model_ex("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long handle = ola.YoloLoadModelEx("models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
YoloLoadModelEx(instance, "models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long YoloLoadModelEx(long ola, string modelPath, string ncnnParamPath, string namesLabel, int modelType, int inferenceType, int inferenceDevice);

long instance = CreateCOLAPlugInterFace();
YoloLoadModelEx(instance, "models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.YoloLoadModelEx(instance, "models/yolov8n.olam", "models/yolov8n.olam", "value", 0, 0, 0)

返回值

返回值说明
> 0成功,返回模型句柄。
负数失败;绝对值为错误码(如 -8006 表示后端加载失败)。与 GetLastError() 一致。

完整错误码表见 YOLO 错误码说明

失败时可调用 GetLastErrorString() / YoloGetLastError() 获取详情。

判断成功请用 handle > 0,不要用 handle != 0

注意事项

项目说明
模块权限需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。

modelType 模型后端类型

含义
0TensorRT Engine(.engine)
1ONNX(.onnx)
2NCNN(.bin + .param 双文件)

inferenceType 推理任务类型

含义
0Detect 目标检测
1Classify 图像分类
2Segment 实例分割
3Pose 姿态估计
4Obb 旋转框检测
  • inferenceDevice-1 表示 CPU;0 及以上表示 GPU 索引。GPU 不可用时可能自动回退 CPU(以实际 ExecutionProvider 为准)。
  • 勿传入加密包路径。
  • namesLabel 三种写法等价:① 文件路径 labels.txt(一行一类);② 内联 person\|car\|bus;③ 内联多行。中文与 GBK 记事本文件均支持,见 类别名称表说明