模型文件存放在assets资源目录下,编译中会一同生成apk打包,如果更新模型也要更新APP,下载并安装。如果单独存储在内存目录,只需检查模型更新并自动下载就可以了。
初始化模型,设置参数为字符串
public native boolean Init(AssetManager mgr,String strP, String strB);
cpp修改参数,字符串转文件
Java_com_***_***_YoloV5Ncnn_Init(JNIEnv* env, jobject thiz, jobject assetManager,
jstring str_param, jstring str_bin){
修改载入文件函数
const char *str_p = env->GetStringUTFChars(str_param, 0);
FILE *pFile = fopen(str_p, "r");
const char *str_b = env->GetStringUTFChars(str_bin, 0);
FILE *bFile = fopen(str_b, "r");
// use vulkan compute
if (ncnn::get_gpu_count() != 0)
opt.use_vulkan_compute = true;
AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
yolov5.opt = opt;
yolov5.register_custom_layer("YoloV5Focus", YoloV5Focus_layer_creator);
{
//int ret = yolov5.load_param(mgr, "lampsim.param");
int ret = yolov5.load_param(pFile);
if (ret != 0) {
__android_log_print(ANDROID_LOG_DEBUG, "YoloV5Ncnn", "load_param failed");
return JNI_FALSE;
}
}
{
//int ret = yolov5.load_model(mgr, "lampsim.bin");
int ret = yolov5.load_model(bFile);
if (ret != 0) {
__android_log_print(ANDROID_LOG_DEBUG, "YoloV5Ncnn", "load_model failed");
return JNI_FALSE;
}
}