Skip to content

解密模型包到文件 - YoloDecryptModel

函数简介

解密加密包,写出明文主模型、可选 NCNN param 与类别名表。

接口名称

YoloDecryptModel

DLL 调用

int YoloDecryptModel(long ola, string packagePath, string password, string modelOutPath, string ncnnParamOutPath, string namesLabelOutPath, int* modelType, int* inferenceType);

参数说明

参数名类型说明
ola长整数型OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。
packagePath字符串加密包路径。
password字符串解密密码。
modelOutPath字符串明文主模型输出路径。
ncnnParamOutPath字符串NCNN .param 输出,可空。
namesLabelOutPath字符串类别名表输出,可空。
modelType整数型*输出:模型后端类型,见下表。
inferenceType整数型*输出:推理任务类型,见下表。

示例

以下示例解密加密包到磁盘;modelType / inferenceType 为输出参数,成功后可读出包头写入的后端与任务类型。非 NCNN 包可将 ncnnParamOutPath 传空。

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int modelType = 0, inferenceType = 0;
int ret = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    modelType, inferenceType);
// 成功后 modelType / inferenceType 为包头中的值
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.YoloDecryptModel(
    @"models\yolov8n.olam", "pwd",
    @"models\yolov8n.onnx", "", @"models\coco.names",
    out int modelType, out int inferenceType);
// 成功后 modelType / inferenceType 为包头中的值
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret, model_type, inference_type = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names")
# 成功后 model_type / inference_type 为包头中的值
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
var result = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names");
// result.ret / result.modelType / result.inferenceType
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
var modelType, inferenceType int32
ret := ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    &modelType, &inferenceType)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let mut model_type: i32 = 0;
let mut inference_type: i32 = 0;
let ret = ola.yolo_decrypt_model(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    &mut model_type, &mut inference_type);
cpp
var ola = com("OlaPlug.OlaSoft")
var modelType = 0, inferenceType = 0
var ret = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    modelType, inferenceType)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
modelType = 0
inferenceType = 0
ret = ola.YoloDecryptModel("models/yolov8n.olam", "pwd", "models/yolov8n.onnx", "", "models/coco.names", modelType, inferenceType)
text
.局部变量 ola, OLAPlug
.局部变量 ret, 整数型
.局部变量 modelType, 整数型
.局部变量 inferenceType, 整数型

ola.创建 ()
ret = ola.YoloDecryptModel (“models/yolov8n.olam”, “pwd”, “models/yolov8n.onnx”, “”, “models/coco.names”, modelType, inferenceType)
' 成功后 modelType / inferenceType 为包头中的值
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var modelType = 0, inferenceType = 0;
var ret = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    modelType, inferenceType);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 modelType = 0, inferenceType = 0
整数 ret = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    modelType, inferenceType)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int modelType = 0, inferenceType = 0;
int ret = ola.YoloDecryptModel(
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    modelType, inferenceType);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
int modelType = 0, inferenceType = 0;
YoloDecryptModel(instance,
    "models/yolov8n.olam", "pwd",
    "models/yolov8n.onnx", "", "models/coco.names",
    &modelType, &inferenceType);
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 YoloDecryptModel(long ola, string packagePath, string password,
    string modelOutPath, string ncnnParamOutPath, string namesLabelOutPath,
    out int modelType, out int inferenceType);

long instance = CreateCOLAPlugInterFace();
YoloDecryptModel(instance,
    @"models\yolov8n.olam", "pwd",
    @"models\yolov8n.onnx", "", @"models\coco.names",
    out int modelType, out int inferenceType);
python
from ctypes import CDLL, c_int, c_int64, byref

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

返回值

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

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

注意事项

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

modelType 模型后端类型

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

inferenceType 推理任务类型

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