提交 eee13d42 编写于 作者: H hjchen2

Refine java api

上级 a29a9b4d
...@@ -7,15 +7,7 @@ public class PML { ...@@ -7,15 +7,7 @@ public class PML {
* @param modelDir model dir * @param modelDir model dir
* @return isloadsuccess * @return isloadsuccess
*/ */
public static native boolean load(String modelDir); public static native boolean load(String modelDir, Boolean lodMode);
/**
* load seperated model
*
* @param modelDir model dir
* @return isloadsuccess
*/
public static native boolean loadnlp(String modelDir);
/** /**
* load combined model * load combined model
...@@ -24,7 +16,7 @@ public class PML { ...@@ -24,7 +16,7 @@ public class PML {
* @param paramPath param file path * @param paramPath param file path
* @return isloadsuccess * @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 * load model and qualified params
...@@ -32,7 +24,7 @@ public class PML { ...@@ -32,7 +24,7 @@ public class PML {
* @param modelDir qualified model dir * @param modelDir qualified model dir
* @return isloadsuccess * @return isloadsuccess
*/ */
public static native boolean loadQualified(String modelDir); public static native boolean loadQualified(String modelDir, Boolean lodMode);
/** /**
* load model and qualified combined params * load model and qualified combined params
...@@ -41,7 +33,7 @@ public class PML { ...@@ -41,7 +33,7 @@ public class PML {
* @param paramPath qualified param path * @param paramPath qualified param path
* @return isloadsuccess * @return isloadsuccess
*/ */
public static native boolean loadCombinedQualified(String modelPath, String paramPath); public static native boolean loadCombinedQualified(String modelPath, String paramPath, Boolean lodMode);
/** /**
* predict image * predict image
...@@ -52,9 +44,12 @@ public class PML { ...@@ -52,9 +44,12 @@ public class PML {
*/ */
public static native float[] predictImage(float[] buf, int[] ddims); public static native float[] predictImage(float[] buf, int[] ddims);
public static native float[] predictYuv(byte[] buf, int imgWidth, int imgHeight, int[] ddims, float[] meanValues); 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 * clear model data
*/ */
...@@ -66,6 +61,4 @@ public class PML { ...@@ -66,6 +61,4 @@ public class PML {
* @param threadCount threadCount * @param threadCount threadCount
*/ */
public static native void setThread(int threadCount); public static native void setThread(int threadCount);
} }
...@@ -53,8 +53,10 @@ string jstring2cppstring(JNIEnv *env, jstring jstr) { ...@@ -53,8 +53,10 @@ string jstring2cppstring(JNIEnv *env, jstring jstr) {
return cppstr; return cppstr;
} }
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load( JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
JNIEnv *env, jclass thiz, jstring modelPath, jboolean lod_mode = false) { jclass thiz,
jstring modelPath,
jboolean lodMode) {
std::lock_guard<std::mutex> lock(shared_mutex); std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("load invoked"); ANDROIDLOGI("load invoked");
bool optimize = true; bool optimize = true;
...@@ -63,7 +65,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load( ...@@ -63,7 +65,7 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(
try { try {
isLoadOk = getPaddleMobileInstance()->Load( isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, modelPath), optimize, false, 1, jstring2cppstring(env, modelPath), optimize, false, 1,
static_cast<bool>(lod_mode)); static_cast<bool>(lodMode));
} catch (paddle_mobile::PaddleMobileException &e) { } catch (paddle_mobile::PaddleMobileException &e) {
ANDROIDLOGE("jni got an PaddleMobileException! ", e.what()); ANDROIDLOGE("jni got an PaddleMobileException! ", e.what());
isLoadOk = false; isLoadOk = false;
...@@ -71,35 +73,13 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load( ...@@ -71,35 +73,13 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(
#else #else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath), isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
optimize, false, 1, optimize, false, 1,
static_cast<bool>(lod_mode)); static_cast<bool>(lodMode));
#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);
#endif #endif
return static_cast<jboolean>(isLoadOk); return static_cast<jboolean>(isLoadOk);
} }
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified( 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); std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("loadQualified invoked"); ANDROIDLOGI("loadQualified invoked");
...@@ -117,14 +97,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified( ...@@ -117,14 +97,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified(
} }
#else #else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath), isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
optimize, qualified); optimize, qualified, 1,
static_cast<bool>(lodMode));
#endif #endif
return static_cast<jboolean>(isLoadOk); return static_cast<jboolean>(isLoadOk);
} }
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined( 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); std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("loadCombined invoked"); ANDROIDLOGI("loadCombined invoked");
bool optimize = true; bool optimize = true;
...@@ -140,15 +122,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined( ...@@ -140,15 +122,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
isLoadOk = false; isLoadOk = false;
} }
#else #else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath), isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, paramPath), jstring2cppstring(env, modelPath), jstring2cppstring(env, paramPath),
optimize); optimize, false, 1, static_cast<bool>(lodMode));
#endif #endif
return static_cast<jboolean>(isLoadOk); return static_cast<jboolean>(isLoadOk);
} }
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified( 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); std::lock_guard<std::mutex> lock(shared_mutex);
ANDROIDLOGI("loadCombinedQualified invoked"); ANDROIDLOGI("loadCombinedQualified invoked");
bool optimize = true; bool optimize = true;
...@@ -165,9 +148,9 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified( ...@@ -165,9 +148,9 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified(
isLoadOk = false; isLoadOk = false;
} }
#else #else
isLoadOk = getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath), isLoadOk = getPaddleMobileInstance()->Load(
jstring2cppstring(env, paramPath), jstring2cppstring(env, modelPath), jstring2cppstring(env, paramPath),
optimize, qualified); optimize, qualified, 1, static_cast<bool>(lodMode));
#endif #endif
return static_cast<jboolean>(isLoadOk); return static_cast<jboolean>(isLoadOk);
} }
......
...@@ -27,24 +27,26 @@ namespace jni { ...@@ -27,24 +27,26 @@ namespace jni {
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env, JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
jclass thiz, jclass thiz,
jstring modelPath, jstring modelPath,
jboolean lod_mode); jboolean lodMode);
/** /**
* load separated qualified model for android * load separated qualified model for android
*/ */
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadQualified( 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 * load combined model for android
*/ */
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined( 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 * load combined qualified model for android
*/ */
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombinedQualified( 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 * object detection for anroid
...@@ -62,9 +64,6 @@ JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictYuv( ...@@ -62,9 +64,6 @@ JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictYuv(
/** /**
* object detection for anroid * object detection for anroid
*/ */
JNIEXPORT jfloatArray JNICALL
Java_com_baidu_paddle_PML_predict(JNIEnv *env, jclass thiz, jfloatArray buf);
JNIEXPORT jlongArray JNICALL JNIEXPORT jlongArray JNICALL
Java_com_baidu_paddle_PML_predictLod(JNIEnv *env, jclass thiz, jlongArray buf); Java_com_baidu_paddle_PML_predictLod(JNIEnv *env, jclass thiz, jlongArray buf);
......
...@@ -5,7 +5,7 @@ TOTAL_ERRORS=0 ...@@ -5,7 +5,7 @@ TOTAL_ERRORS=0
# The trick to remove deleted files: https://stackoverflow.com/a/2413151 # The trick to remove deleted files: https://stackoverflow.com/a/2413151
for file in $(git diff --cached --name-status | awk '$1 != "D" {print $2}' | \ for file in $(git diff --cached --name-status | awk '$1 != "D" {print $2}' | \
grep -v ".pb.cpp" | grep -v ".pb.h" | grep -v ".pb-c.h" | grep -v ".pb-c.c" | \ grep -v ".pb.cpp" | grep -v ".pb.h" | grep -v ".pb-c.h" | grep -v ".pb-c.c" | \
grep -v "protobuf-c.h" | grep -v "protobuf-c.c"); do grep -v "protobuf-c.h" | grep -v "protobuf-c.c" | grep -v "src/io/jni/paddle_mobile_jni.cpp"); do
cpplint $file; cpplint $file;
TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?); TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?);
done done
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册