提交 b725e171 编写于 作者: H Houjiang Chen 提交者: GitHub

Merge pull request #1406 from hjchen2/ci_build

refine java api
......@@ -7,15 +7,7 @@ public class PML {
* @param modelDir model dir
* @return isloadsuccess
*/
public static native boolean load(String modelDir);
/**
* load seperated model
*
* @param modelDir model dir
* @return isloadsuccess
*/
public static native boolean loadnlp(String modelDir);
public static native boolean load(String modelDir, Boolean lodMode);
/**
* load combined model
......@@ -24,7 +16,7 @@ public class PML {
* @param paramPath param file path
* @return isloadsuccess
*/
public static native boolean loadCombined(String modelPath, String paramPath);
public static native boolean loadCombined(String modelPath, String paramPath, Boolean lodMode);
/**
* load model and qualified params
......@@ -32,7 +24,7 @@ public class PML {
* @param modelDir qualified model dir
* @return isloadsuccess
*/
public static native boolean loadQualified(String modelDir);
public static native boolean loadQualified(String modelDir, Boolean lodMode);
/**
* load model and qualified combined params
......@@ -41,7 +33,7 @@ public class PML {
* @param paramPath qualified param path
* @return isloadsuccess
*/
public static native boolean loadCombinedQualified(String modelPath, String paramPath);
public static native boolean loadCombinedQualified(String modelPath, String paramPath, Boolean lodMode);
/**
* predict image
......@@ -52,9 +44,12 @@ public class PML {
*/
public static native float[] predictImage(float[] buf, int[] ddims);
public static native float[] predictYuv(byte[] buf, int imgWidth, int imgHeight, int[] ddims, float[] meanValues);
// predict with variable length input
// support only one input and one output currently
public static native float[] predictLod(float[] buf);
/**
* clear model data
*/
......@@ -66,6 +61,4 @@ public class PML {
* @param threadCount threadCount
*/
public static native void setThread(int threadCount);
}
......@@ -53,8 +53,10 @@ string jstring2cppstring(JNIEnv *env, jstring jstr) {
return cppstr;
}
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(
JNIEnv *env, jclass thiz, jstring modelPath, jboolean lod_mode = false) {
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
jclass thiz,
jstring modelPath,
jboolean lodMode) {
std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("load invoked");
bool optimize = true;
......@@ -63,7 +65,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(
try {
isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, modelPath), optimize, false, 1,
static_cast<bool>(lod_mode));
static_cast<bool>(lodMode));
} catch (paddle_mobile::PaddleMobileException &e) {
ANDROIDLOGE("jni got an PaddleMobileException! ", e.what());
isLoadOk = false;
......@@ -71,35 +73,13 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(
#else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
optimize, false, 1,
static_cast<bool>(lod_mode));
#endif
return static_cast<jboolean>(isLoadOk);
}
JNIEXPORT jboolean JNICALL
Java_com_baidu_paddle_PML_loadnlp(JNIEnv *env, jclass thiz, jstring modelPath) {
std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("load invoked");
bool optimize = true;
bool isLoadOk = false;
#ifdef ENABLE_EXCEPTION
try {
isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, modelPath), optimize, false, 1, true);
} catch (paddle_mobile::PaddleMobileException &e) {
ANDROIDLOGE("jni got an PaddleMobileException! ", e.what());
isLoadOk = false;
}
#else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
optimize, false, 1, true);
static_cast<bool>(lodMode));
#endif
return static_cast<jboolean>(isLoadOk);
}
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified(
JNIEnv *env, jclass thiz, jstring modelPath) {
JNIEnv *env, jclass thiz, jstring modelPath, jboolean lodMode) {
std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("loadQualified invoked");
......@@ -117,14 +97,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified(
}
#else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
optimize, qualified);
optimize, qualified, 1,
static_cast<bool>(lodMode));
#endif
return static_cast<jboolean>(isLoadOk);
}
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath) {
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath,
jboolean lodMode) {
std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("loadCombined invoked");
bool optimize = true;
......@@ -140,15 +122,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
isLoadOk = false;
}
#else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
jstring2cppstring(env, paramPath),
optimize);
isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, modelPath), jstring2cppstring(env, paramPath),
optimize, false, 1, static_cast<bool>(lodMode));
#endif
return static_cast<jboolean>(isLoadOk);
}
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified(
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath) {
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath,
jboolean lodMode) {
std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("loadCombinedQualified invoked");
bool optimize = true;
......@@ -165,9 +148,9 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified(
isLoadOk = false;
}
#else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
jstring2cppstring(env, paramPath),
optimize, qualified);
isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, modelPath), jstring2cppstring(env, paramPath),
optimize, qualified, 1, static_cast<bool>(lodMode));
#endif
return static_cast<jboolean>(isLoadOk);
}
......
......@@ -27,24 +27,26 @@ namespace jni {
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
jclass thiz,
jstring modelPath,
jboolean lod_mode);
jboolean lodMode);
/**
* load separated qualified model for android
*/
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified(
JNIEnv *env, jclass thiz, jstring modelPath);
JNIEnv *env, jclass thiz, jstring modelPath, jboolean lodMode);
/**
* load combined model for android
*/
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath);
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath,
jboolean lodMode);
/**
* load combined qualified model for android
*/
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified(
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath);
JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath,
jboolean lodMode);
/**
* object detection for anroid
......@@ -62,9 +64,6 @@ JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictYuv(
/**
* object detection for anroid
*/
JNIEXPORT jfloatArray JNICALL
Java_com_baidu_paddle_PML_predict(JNIEnv *env, jclass thiz, jfloatArray buf);
JNIEXPORT jlongArray JNICALL
Java_com_baidu_paddle_PML_predictLod(JNIEnv *env, jclass thiz, jlongArray buf);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册