Skip to content

加密模型包到文件 - YoloEncryptModel

函数简介

将明文模型与可选类别名表打成欧拉加密包并写入磁盘;包头写入 modelType、inferenceType。

接口名称

YoloEncryptModel

DLL 调用

int YoloEncryptModel(long ola, string modelPath, string ncnnParamPath, string namesLabel, string password, int modelType, int inferenceType, string savePath);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
modelPath字符串主模型路径。
ncnnParamPath字符串NCNN .param,可空。
namesLabel字符串类别名称:可选。文件路径或内联 |/多行文本;编码自动识别。详见 类别名称表说明
password字符串加密密码。
modelType整数型模型后端类型,见下表。
inferenceType整数型推理任务类型,见下表。
savePath字符串输出加密包路径。

示例

以下示例以 ONNX 单文件 加密为目标检测包:ncnnParamPath 传空,modelType=1inferenceType=0。NCNN 需额外传入 .parammodelType=2

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
    @"models\yolov8n.onnx", "", @"models\coco.names",
    "pwd", 1, 0, @"models\yolov8n.olam");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret := ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam")
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
let ret = ola.yolo_encrypt_model(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam");
cpp
var ola = com("OlaPlug.OlaSoft")
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
var ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret = ola.YoloEncryptModel("models/yolov8n.onnx", "", "models/coco.names", "pwd", 1, 0, "models/yolov8n.olam")
text
.局部变量 ola, OLAPlug
.局部变量 ret, 整数型

ola.创建 ()
' ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret = ola.YoloEncryptModel (“models/yolov8n.onnx”, “”, “models/coco.names”, “pwd”, 1, 0, “models/yolov8n.olam”)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
var ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
整数 ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
YoloEncryptModel(instance,
    "models/yolov8n.onnx", "", "models/coco.names",
    "pwd", 1, 0, "models/yolov8n.olam");
csharp
using System.Runtime.InteropServices;

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

long instance = CreateCOLAPlugInterFace();
YoloEncryptModel(instance,
    @"models\yolov8n.onnx", "", @"models\coco.names",
    "pwd", 1, 0, @"models\yolov8n.olam");
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.YoloEncryptModel.restype = c_int
instance = ola.CreateCOLAPlugInterFace()
ola.YoloEncryptModel(
    instance,
    b"models/yolov8n.onnx", b"", b"models/coco.names",
    b"pwd", 1, 0, b"models/yolov8n.olam")

返回值

返回值说明
1成功。
负数失败;绝对值为错误码。与 GetLastError() 一致。

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

注意事项

项目说明
模块权限需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。
路径namesLabel 支持文件路径、内联 `

modelType 模型后端类型

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

inferenceType 推理任务类型

含义
0Detect 目标检测
1Classify 图像分类
2Segment 实例分割
3Pose 姿态估计
4Obb 旋转框检测