|
5#
楼主 |
发表于 2019-3-6 09:57:55
|
只看该作者
int load_model(std::vector<const char *>& net,
std::vector<rknn_context> &ctx)
{
FILE *fp;
int model_len=0;
int ret = 0;
rknn_context context=0;
rknn_context context_2=0;
// load rknn model1
fp = fopen(net[0], "rb");
if(fp == NULL) {
printf("fopen %s fail!\n", net[0]);
return -1;
}
fseek(fp, 0, SEEK_END);
model_len = ftell(fp);
model_net_1 = malloc(model_len);
fseek(fp, 0, SEEK_SET);
if(model_len != fread(model_net_1, 1, model_len, fp)) {
printf("fread %s fail!\n", net[0]);
free(model_net_1);
return -1;
}
printf("model_len:%d\n",model_len);
// rknn_init
ret = rknn_init(&context, model_net_1, model_len, RKNN_FLAG_PRIOR_MEDIUM);
if(ret < 0) {
printf("rknn_init fail! ret=%d\n", ret);
source_release(context, model_net_1);
return -1;
}
ctx.push_back(context);
printf("[debug] ctx[0]:%ld\n",context);
fclose(fp);
model_len = 0;
// load rknn model2
fp = fopen(net[1], "rb");
if(fp == NULL) {
printf("fopen %s fail!\n", net[1]);
return -1;
}
fseek(fp, 0, SEEK_END);
model_len = ftell(fp);
model_net_2 = malloc(model_len);
fseek(fp, 0, SEEK_SET);
if(model_len != fread(model_net_2, 1, model_len, fp)) {
printf("fread %s fail!\n", net[1]);
free(model_net_2);
return -1;
}
printf("model_len:%d\n",model_len);
// rknn_init
ret = rknn_init(&context_2, model_net_2, model_len, RKNN_FLAG_PRIOR_MEDIUM);
if(ret < 0) {
printf("rknn_init fail! ret=%d\n", ret);
source_release(context_2, model_net_2);
return -1;
}
ctx.push_back(context_2);
printf("[debug] ctx[1]:%ld\n",context_2);
fclose(fp);
free(model_net_1);
free(model_net_2);
return 0;
}
我定义了2个context,运行后错误信息如下:
model_len:17347
[debug] ctx[0]:416131600
model_len:17350
rknn_init fail! ret=-6
ctx.size:1
只能注册一个模型...
|
|