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 {
...
@@ -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
);
}
}
src/io/jni/paddle_mobile_jni.cpp
浏览文件 @
eee13d42
...
@@ -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
_m
ode
));
static_cast
<
bool
>
(
lod
M
ode
));
}
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
);
}
}
...
...
src/io/jni/paddle_mobile_jni.h
浏览文件 @
eee13d42
...
@@ -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
_m
ode
);
jboolean
lod
M
ode
);
/**
/**
* 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
);
...
...
tools/pre-commit.hooks/cpplint.hook
浏览文件 @
eee13d42
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录