Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
c6554d1c
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看板
提交
c6554d1c
编写于
6月 08, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support combine format fluid model
上级
262bab3d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
28 deletion
+19
-28
CMakeLists.txt
CMakeLists.txt
+10
-7
src/io/io.cpp
src/io/io.cpp
+5
-15
src/io/io.h
src/io/io.h
+1
-2
test/net/test_googlenet.cpp
test/net/test_googlenet.cpp
+3
-4
未找到文件。
CMakeLists.txt
浏览文件 @
c6554d1c
...
@@ -5,19 +5,22 @@ option(DEBUGING "enable debug mode" OFF)
...
@@ -5,19 +5,22 @@ option(DEBUGING "enable debug mode" OFF)
option
(
USE_OPENMP
"openmp support"
OFF
)
option
(
USE_OPENMP
"openmp support"
OFF
)
option
(
USE_EXCEPTION
"use std exception"
OFF
)
option
(
USE_EXCEPTION
"use std exception"
OFF
)
set
(
CMAKE_BUILD_TYPE Debug
)
if
(
DEBUGING
)
if
(
DEBUGING
)
set
(
CMAKE_BUILD_TYPE Debug
)
else
()
else
()
set
(
CMAKE_BUILD_TYPE Release
)
#
set(CMAKE_BUILD_TYPE Release)
endif
()
endif
()
add_definitions
(
-DPADDLE_MOBILE_DEBUG
)
if
(
DEBUGING
)
if
(
DEBUGING
)
message
(
STATUS
"debuging"
)
#
message(STATUS "debuging")
add_definitions
(
-DPADDLE_MOBILE_DEBUG
)
else
()
else
()
message
(
STATUS
"releasing"
)
#
message(STATUS "releasing")
add_definitions
(
-fvisibility=hidden -fvisibility-inlines-hidden
)
#
add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
endif
()
endif
()
if
(
USE_EXCEPTION
)
if
(
USE_EXCEPTION
)
...
@@ -122,8 +125,8 @@ endif()
...
@@ -122,8 +125,8 @@ endif()
add_library
(
paddle-mobile SHARED
${
PADDLE_MOBILE_CC
}
${
PADDLE_MOBILE_H
}
)
add_library
(
paddle-mobile SHARED
${
PADDLE_MOBILE_CC
}
${
PADDLE_MOBILE_H
}
)
add_subdirectory
(
test
)
if
(
DEBUGING
)
if
(
DEBUGING
)
add_subdirectory
(
test
)
endif
()
endif
()
src/io/io.cpp
浏览文件 @
c6554d1c
...
@@ -279,17 +279,14 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
...
@@ -279,17 +279,14 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
template
<
typename
Dtype
,
Precision
P
>
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
LoadMemory
(
const
framework
::
VarDesc
var_desc
,
void
Executor
<
Dtype
,
P
>::
LoadMemory
(
const
framework
::
VarDesc
var_desc
,
framework
::
LoDTensor
*
tensor
,
framework
::
LoDTensor
*
tensor
,
char
*&
data
)
{
const
std
::
string
&
file_path
,
char
*
data
)
{
// 1. version
// 1. version
uint32_t
version
=
*
(
uint32_t
*
)
data
;
uint32_t
version
=
*
(
uint32_t
*
)
data
;
data
+=
sizeof
(
uint32_t
);
data
+=
sizeof
(
uint32_t
);
DLOG
<<
"version: "
<<
version
;
// 2 Lod information
// 2 Lod information
uint64_t
lod_level
=
*
(
uint64_t
*
)
data
;
uint64_t
lod_level
=
*
(
uint64_t
*
)
data
;
data
+=
sizeof
(
uint64_t
);
data
+=
sizeof
(
uint64_t
);
DLOG
<<
"lod_level: "
<<
lod_level
;
auto
&
lod
=
*
tensor
->
mutable_lod
();
auto
&
lod
=
*
tensor
->
mutable_lod
();
lod
.
resize
(
lod_level
);
lod
.
resize
(
lod_level
);
...
@@ -297,7 +294,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
...
@@ -297,7 +294,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
uint64_t
size
=
*
(
uint64_t
*
)
data
;
uint64_t
size
=
*
(
uint64_t
*
)
data
;
data
+=
sizeof
(
uint64_t
);
data
+=
sizeof
(
uint64_t
);
DLOG
<<
"lod size: "
<<
i
<<
size
;
DLOG
<<
"lod size: "
<<
i
<<
size
;
std
::
vector
<
size_t
>
tmp
(
size
/
sizeof
(
size_t
));
std
::
vector
<
size_t
>
tmp
(
size
/
sizeof
(
size_t
));
for
(
int
k
=
0
;
k
<
tmp
.
size
();
++
k
)
{
for
(
int
k
=
0
;
k
<
tmp
.
size
();
++
k
)
{
...
@@ -315,12 +311,10 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
...
@@ -315,12 +311,10 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
// 3. tensor version
// 3. tensor version
uint32_t
tensor_version
=
*
(
uint32_t
*
)
data
;
uint32_t
tensor_version
=
*
(
uint32_t
*
)
data
;
data
+=
sizeof
(
uint32_t
);
data
+=
sizeof
(
uint32_t
);
DLOG
<<
"tensor_version: "
<<
tensor_version
;
// 4. tensor desc
// 4. tensor desc
int32_t
size
=
*
(
int32_t
*
)
data
;
int32_t
size
=
*
(
int32_t
*
)
data
;
data
+=
sizeof
(
int32_t
);
data
+=
sizeof
(
int32_t
);
DLOG
<<
"tensor desc size: "
<<
size
;
std
::
unique_ptr
<
char
[]
>
buf
(
new
char
[
size
]);
std
::
unique_ptr
<
char
[]
>
buf
(
new
char
[
size
]);
for
(
int
m
=
0
;
m
<
size
;
++
m
)
{
for
(
int
m
=
0
;
m
<
size
;
++
m
)
{
...
@@ -344,7 +338,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
...
@@ -344,7 +338,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
break
;
break
;
case
framework
::
VARTYPE_TYPE_FP32
:
case
framework
::
VARTYPE_TYPE_FP32
:
type_size
=
4
;
type_size
=
4
;
DLOG
<<
" type size: "
<<
type_size
;
memory
=
tensor
->
mutable_data
<
float
>
();
memory
=
tensor
->
mutable_data
<
float
>
();
break
;
break
;
case
framework
::
VARTYPE_TYPE_FP64
:
case
framework
::
VARTYPE_TYPE_FP64
:
...
@@ -382,8 +375,8 @@ void Executor<Dtype, P>::InitMemory() {
...
@@ -382,8 +375,8 @@ void Executor<Dtype, P>::InitMemory() {
char
*
origin_data
=
char
*
origin_data
=
Get_binary_data
(
program_
.
model_path
+
"/"
+
var_desc
->
Name
());
Get_binary_data
(
program_
.
model_path
+
"/"
+
var_desc
->
Name
());
LoadMemory
(
*
var_desc
,
tensor
,
char
*
data
=
origin_data
;
program_
.
model_path
+
"/"
+
var_desc
->
Name
(),
origin_
data
);
LoadMemory
(
*
var_desc
,
tensor
,
data
);
delete
origin_data
;
delete
origin_data
;
}
else
{
}
else
{
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
...
@@ -399,7 +392,7 @@ void Executor<Dtype, P>::InitMemory() {
...
@@ -399,7 +392,7 @@ void Executor<Dtype, P>::InitMemory() {
template
<
typename
Dtype
,
Precision
P
>
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
InitCombineMemory
()
{
void
Executor
<
Dtype
,
P
>::
InitCombineMemory
()
{
char
*
origin_data
=
Get_binary_data
(
program_
.
para_path
);
char
*
origin_data
=
Get_binary_data
(
program_
.
para_path
);
char
*
data
=
origin_data
;
for
(
const
auto
&
block
:
to_predict_program_
->
Blocks
())
{
for
(
const
auto
&
block
:
to_predict_program_
->
Blocks
())
{
for
(
const
auto
&
var_desc
:
block
->
Vars
())
{
for
(
const
auto
&
var_desc
:
block
->
Vars
())
{
auto
var
=
program_
.
scope
->
Var
(
var_desc
->
Name
());
auto
var
=
program_
.
scope
->
Var
(
var_desc
->
Name
());
...
@@ -408,18 +401,15 @@ void Executor<Dtype, P>::InitCombineMemory() {
...
@@ -408,18 +401,15 @@ void Executor<Dtype, P>::InitCombineMemory() {
if
(
var_desc
->
Name
()
==
"feed"
||
var_desc
->
Name
()
==
"fetch"
)
{
if
(
var_desc
->
Name
()
==
"feed"
||
var_desc
->
Name
()
==
"fetch"
)
{
continue
;
continue
;
}
}
LoadMemory
(
*
var_desc
,
tensor
,
LoadMemory
(
*
var_desc
,
tensor
,
data
);
program_
.
model_path
+
"/"
+
var_desc
->
Name
(),
origin_data
);
}
else
{
}
else
{
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
auto
tensor
=
var
->
template
GetMutable
<
framework
::
LoDTensor
>();
auto
tensor
=
var
->
template
GetMutable
<
framework
::
LoDTensor
>();
tensor
->
template
mutable_data
<
Ptype
>();
tensor
->
template
mutable_data
<
Ptype
>();
}
}
}
}
}
}
}
}
delete
origin_data
;
delete
origin_data
;
}
}
...
...
src/io/io.h
浏览文件 @
c6554d1c
...
@@ -63,8 +63,7 @@ class Executor {
...
@@ -63,8 +63,7 @@ class Executor {
void
InitMemory
();
void
InitMemory
();
void
LoadMemory
(
const
framework
::
VarDesc
var_desc
,
void
LoadMemory
(
const
framework
::
VarDesc
var_desc
,
framework
::
LoDTensor
*
tensor
,
const
std
::
string
&
file_path
,
framework
::
LoDTensor
*
tensor
,
char
*&
data
);
char
*
data
);
void
InitCombineMemory
();
void
InitCombineMemory
();
framework
::
Program
<
Dtype
>
program_
;
framework
::
Program
<
Dtype
>
program_
;
int
batch_size_
=
1
;
int
batch_size_
=
1
;
...
...
test/net/test_googlenet.cpp
浏览文件 @
c6554d1c
...
@@ -20,10 +20,9 @@ int main() {
...
@@ -20,10 +20,9 @@ int main() {
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
bool
optimize
=
false
;
bool
optimize
=
false
;
auto
time1
=
time
();
auto
time1
=
time
();
// auto program = loader.Load(g_googlenet, optimize);
auto
program
=
loader
.
Load
(
g_googlenet
,
optimize
);
auto
program
=
loader
.
Load
(
g_googlenet_combine
+
"/model"
,
// auto program = loader.Load(g_googlenet_combine + "/model",
g_googlenet_combine
+
"/params"
,
optimize
);
// g_googlenet_combine + "/params", optimize);
auto
time2
=
time
();
auto
time2
=
time
();
DLOG
<<
"load cost :"
<<
time_diff
(
time1
,
time2
)
<<
"ms
\n
"
;
DLOG
<<
"load cost :"
<<
time_diff
(
time1
,
time2
)
<<
"ms
\n
"
;
paddle_mobile
::
Executor
<
paddle_mobile
::
CPU
>
executor
(
program
,
1
,
optimize
);
paddle_mobile
::
Executor
<
paddle_mobile
::
CPU
>
executor
(
program
,
1
,
optimize
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录