Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
eee13d42
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
eee13d42
编写于
1月 22, 2019
作者:
H
hjchen2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine java api
上级
a29a9b4d
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
34 addition
and
59 deletion
+34
-59
src/io/jni/PML.java
src/io/jni/PML.java
+8
-15
src/io/jni/paddle_mobile_jni.cpp
src/io/jni/paddle_mobile_jni.cpp
+19
-36
src/io/jni/paddle_mobile_jni.h
src/io/jni/paddle_mobile_jni.h
+6
-7
tools/pre-commit.hooks/cpplint.hook
tools/pre-commit.hooks/cpplint.hook
+1
-1
未找到文件。
src/io/jni/PML.java
浏览文件 @
eee13d42
...
...
@@ -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
);
}
src/io/jni/paddle_mobile_jni.cpp
浏览文件 @
eee13d42
...
...
@@ -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
_m
ode
));
static_cast
<
bool
>
(
lod
M
ode
));
}
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
);
}
...
...
src/io/jni/paddle_mobile_jni.h
浏览文件 @
eee13d42
...
...
@@ -27,24 +27,26 @@ namespace jni {
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_PML_load
(
JNIEnv
*
env
,
jclass
thiz
,
jstring
modelPath
,
jboolean
lod
_m
ode
);
jboolean
lod
M
ode
);
/**
* 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
);
...
...
tools/pre-commit.hooks/cpplint.hook
浏览文件 @
eee13d42
...
...
@@ -5,7 +5,7 @@ TOTAL_ERRORS=0
# The trick to remove deleted files: https://stackoverflow.com/a/2413151
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
"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
;
TOTAL_ERRORS
=
$(
expr
$TOTAL_ERRORS
+
$?
)
;
done
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录