跳到主要内容

属性

构造/调用失败按 C 惯例看 int32_t 返回码(0 成功),详情看 darra_model_last_error。

类型与约定​

类型索引:darra_model(不透明句柄)、darra_model_config(实例配置)、darra_diag(环境诊断快照)、darra_key_options(出包签发选项)。图像描述用 darra_image_desc + darra_image_format,format = AUTO / ENCODED / RGB888 / BGR888 / GRAY8 / RGBA8888 / BGRA8888。

类别属性类型读写说明
元信息darra_model_meta_path()`const char*`只读模型文件路径,就是 create 传入的原值;串在句柄内缓冲里,别释放
darra_model_meta_task()`const char*`只读任务短名(detect / classify / segment / pose / obb / ocr / anomaly / depth);串在句柄内缓冲里,别释放
darra_model_meta_label_count()`size_t`只读类别名表里一共有几条
darra_model_meta_label_at()`const char*`只读按下标取一个类别名,越界 / 没表返回 NULL;串在句柄内缓冲里,别释放
darra_model_meta_class_count()`int32_t`只读类别数,结果写进出参 int64_t*;没声明时返回非 0
darra_model_meta_input_width()`int32_t`只读元信息里写的输入宽度(出参 int64_t*);没声明就写 0
darra_model_meta_input_height()`int32_t`只读元信息里写的输入高度(出参 int64_t*);没声明就写 0
darra_model_meta_input_channels()`int32_t`只读元信息里写的输入通道数(出参 int64_t*);没声明就写 0
darra_model_meta_is_encrypted()`int32_t`只读这个容器是不是加密的;create 后就能读
darra_model_meta_json()`const char*`只读元信息的原始 JSON;没有就返回空串,串在句柄内缓冲里,别释放;open 后按会话声明值刷新
状态darra_model_license()`int32_t`只读授权态五态:未 open / 明文 / 试用 / 绑定中 / 已绑定;和 phase 是两回事
darra_model_phase()`int32_t`只读生命周期走到了哪一步:Loaded / Opened / Error;推理失败不改相位
darra_model_last_error()`const char*`只读最近一次失败给人看的文案;串在句柄内缓冲里
darra_model_last_error_code()`int32_t`只读最近一次失败的错误码
darra_model_last_error_category()`int32_t`只读最近一次失败归到哪一类

状态管理​

时机看哪个属性预期
darra_model_open() 前darra_model_phase() / darra_model_license()LOADED / NOT_OPENED
darra_model_open() 后darra_model_license() / darra_model_phase()明文 / 试用 / 绑定中 / 已绑定 之一;OPENED
推理失败时darra_model_last_error_code()非 0;darra_model_phase() 仍 OPENED
darra_model_close() 后darra_model_license() / darra_model_phase()NOT_OPENED / LOADED

完整示例​

#include "darra_model.h"
#include <stdio.h>

int main(void) {
/* 1. 零初始化 config:全 0/NULL = 默认 */
darra_model_config cfg = {0};

/* 2. create:登记配置 + 加载元信息 */
darra_model* m = NULL;
if (darra_model_create("model.darmodel", &cfg, &m) != DARRA_OK) {
return 1; /* create 失败无句柄,直接收场 */
}
printf("task=%s\n", darra_model_meta_task(m)); /* create 后元信息即可读 */

/* 3. open:加载会话;NULL / 空串 = 无需密码 */
if (!darra_model_open(m, NULL)) {
printf("open failed: %s\n", darra_model_last_error(m));
darra_model_close(m);
return 1;
}

/* 4. infer_file_ex:本次阈值覆盖(NULL = 走 default_thresholds) */
static const double thr[2] = { 0.6, 0.9 };
char* json = NULL;
int32_t rc = darra_model_infer_file_ex(m, "a.jpg", thr, 2, &json);
if (rc == DARRA_OK) {
printf("%s\n", json);
darra_string_free(json); /* 结果 JSON 必须释放,不释放即泄漏 */
} else {
/* 出错:返回码 + last_error 一起看;缺包就 darra_diag_fill 查缺什么 */
darra_diag d = {0};
d.size = sizeof(d);
darra_diag_fill(&d);
printf("supported=%d\n", darra_diag_supported(&d));
printf("infer failed %d: %s\n", rc, darra_model_last_error(m));
}

/* 5. 状态:授权态 / 相位 / last_error */
printf("license=%d phase=%d err=%s\n",
darra_model_license(m), darra_model_phase(m), darra_model_last_error(m));

/* 6. close:生命周期终点,NULL 安全 */
darra_model_close(m);
return 0;
}