Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
88c8a6d7
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看板
提交
88c8a6d7
编写于
5月 29, 2018
作者:
W
WangLiu
提交者:
GitHub
5月 29, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #308 from cocodark/develop
refine unit test
上级
aaa7bc2b
f4b27958
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
10 addition
and
55 deletion
+10
-55
src/framework/op_registry.h
src/framework/op_registry.h
+0
-8
src/io.cpp
src/io.cpp
+4
-30
src/operators/kernel/arm/conv_kernel.cpp
src/operators/kernel/arm/conv_kernel.cpp
+2
-9
test/executor_for_test.h
test/executor_for_test.h
+3
-3
test/operators/test_sigmoid_op.cpp
test/operators/test_sigmoid_op.cpp
+0
-4
test/operators/test_softmax_op.cpp
test/operators/test_softmax_op.cpp
+1
-1
未找到文件。
src/framework/op_registry.h
浏览文件 @
88c8a6d7
...
@@ -90,14 +90,6 @@ class OpRegistry {
...
@@ -90,14 +90,6 @@ class OpRegistry {
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
std
::
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
attrs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
attrs
,
std
::
shared_ptr
<
paddle_mobile
::
framework
::
Scope
>
scope
)
{
std
::
shared_ptr
<
paddle_mobile
::
framework
::
Scope
>
scope
)
{
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
" type: "
<<
type
;
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
" input size: "
<<
inputs
.
size
();
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
" output size: "
<<
outputs
.
size
();
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
" attr size: "
<<
attrs
.
size
();
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
" OpInfoMap size: "
<<
OpInfoMap
<
Dtype
>::
Instance
()
->
map
().
size
();
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
" has type: "
<<
type
<<
" "
<<
OpInfoMap
<
Dtype
>::
Instance
()
->
Has
(
type
);
auto
&
info
=
OpInfoMap
<
Dtype
>::
Instance
()
->
Get
(
type
);
auto
&
info
=
OpInfoMap
<
Dtype
>::
Instance
()
->
Get
(
type
);
auto
op
=
info
.
Creator
()(
type
,
inputs
,
outputs
,
attrs
,
scope
);
auto
op
=
info
.
Creator
()(
type
,
inputs
,
outputs
,
attrs
,
scope
);
return
std
::
shared_ptr
<
OperatorBase
<
Dtype
>>
(
op
);
return
std
::
shared_ptr
<
OperatorBase
<
Dtype
>>
(
op
);
...
...
src/io.cpp
浏览文件 @
88c8a6d7
...
@@ -45,7 +45,7 @@ static size_t ReadBuffer(const char *file_name, uint8_t **out) {
...
@@ -45,7 +45,7 @@ static size_t ReadBuffer(const char *file_name, uint8_t **out) {
printf
(
"%s
\n
"
,
file_name
);
printf
(
"%s
\n
"
,
file_name
);
FILE
*
fp
;
FILE
*
fp
;
fp
=
fopen
(
file_name
,
"rb"
);
fp
=
fopen
(
file_name
,
"rb"
);
PADDLE_MOBILE_ENFORCE
(
fp
!=
NULL
,
"
open failed !"
);
PADDLE_MOBILE_ENFORCE
(
fp
!=
NULL
,
"
%s open failed !"
,
file_name
);
fseek
(
fp
,
0
,
SEEK_END
);
fseek
(
fp
,
0
,
SEEK_END
);
size_t
size
=
ftell
(
fp
);
size_t
size
=
ftell
(
fp
);
...
@@ -210,7 +210,7 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
...
@@ -210,7 +210,7 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
tensor
->
Resize
(
framework
::
make_ddim
(
dim
));
tensor
->
Resize
(
framework
::
make_ddim
(
dim
));
}
else
{
}
else
{
auto
dim
=
var_desc
->
Tensor_desc
().
Dims
();
auto
dim
=
var_desc
->
Tensor_desc
().
Dims
();
PADDLE_MOBILE_ENFORCE
(
dim
.
size
()
>
1
,
"dim size is 0"
);
PADDLE_MOBILE_ENFORCE
(
dim
.
size
()
>
0
,
"dim size is 0"
);
dim
[
0
]
=
1
;
dim
[
0
]
=
1
;
auto
tensor
=
var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
tensor
=
var
->
GetMutable
<
framework
::
LoDTensor
>
();
tensor
->
Resize
(
framework
::
make_ddim
(
dim
));
tensor
->
Resize
(
framework
::
make_ddim
(
dim
));
...
@@ -380,7 +380,8 @@ void Executor<Dtype, P>::InitMemory() {
...
@@ -380,7 +380,8 @@ void Executor<Dtype, P>::InitMemory() {
program_
.
model_path
+
"/"
+
var_desc
->
Name
());
program_
.
model_path
+
"/"
+
var_desc
->
Name
());
}
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
::
Tensor
>();
auto
tensor
=
var
->
template
GetMutable
<
framework
::
LoDTensor
>();
tensor
->
template
mutable_data
<
Ptype
>();
tensor
->
template
mutable_data
<
Ptype
>();
}
}
}
}
...
@@ -388,39 +389,12 @@ void Executor<Dtype, P>::InitMemory() {
...
@@ -388,39 +389,12 @@ void Executor<Dtype, P>::InitMemory() {
}
}
}
}
template
<
typename
Dtype
,
Precision
P
>
std
::
shared_ptr
<
framework
::
Tensor
>
Executor
<
Dtype
,
P
>::
predict
(
framework
::
Tensor
&
t
)
{
// feed
auto
scope
=
program_
.
scope
;
framework
::
Variable
*
g_feed_value
=
scope
->
Var
(
"pixel"
);
auto
tensor
=
g_feed_value
->
GetMutable
<
framework
::
Tensor
>
();
tensor
->
ShareDataWith
(
t
);
framework
::
Variable
*
con_output
=
scope
->
Var
(
"conv2d_0.tmp_0"
);
framework
::
Tensor
*
output_tensor
=
con_output
->
GetMutable
<
framework
::
Tensor
>
();
output_tensor
->
mutable_data
<
float
>
({
1
,
16
,
32
,
32
});
// std::cout << typeid(output_tensor).name() << std::endl;
// std::cout << "output_tensor dims: " << output_tensor->dims() <<
// std::endl;
std
::
shared_ptr
<
framework
::
Tensor
>
out_tensor
=
std
::
make_shared
<
framework
::
LoDTensor
>
();
out_tensor
.
reset
(
output_tensor
);
predict
(
t
,
0
);
return
out_tensor
;
}
template
<
typename
Dtype
,
Precision
P
>
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
predict
(
const
framework
::
Tensor
&
t
,
int
block_id
)
{
void
Executor
<
Dtype
,
P
>::
predict
(
const
framework
::
Tensor
&
t
,
int
block_id
)
{
framework
::
Variable
*
g_feed_value
=
program_
.
scope
->
Var
(
"feed"
);
framework
::
Variable
*
g_feed_value
=
program_
.
scope
->
Var
(
"feed"
);
auto
feed_tensor
=
g_feed_value
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
feed_tensor
=
g_feed_value
->
GetMutable
<
framework
::
LoDTensor
>
();
feed_tensor
->
Resize
(
t
.
dims
());
feed_tensor
->
Resize
(
t
.
dims
());
feed_tensor
->
ShareDataWith
(
t
);
feed_tensor
->
ShareDataWith
(
t
);
std
::
shared_ptr
<
framework
::
BlockDesc
>
to_predict_block
=
std
::
shared_ptr
<
framework
::
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
block_id
);
to_predict_program_
->
Block
(
block_id
);
for
(
int
j
=
0
;
j
<
ops_of_block_
[
*
to_predict_block
.
get
()].
size
();
++
j
)
{
for
(
int
j
=
0
;
j
<
ops_of_block_
[
*
to_predict_block
.
get
()].
size
();
++
j
)
{
...
...
src/operators/kernel/arm/conv_kernel.cpp
浏览文件 @
88c8a6d7
...
@@ -44,13 +44,13 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
...
@@ -44,13 +44,13 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
std
::
vector
<
int
>
paddings
=
param
.
Paddings
();
std
::
vector
<
int
>
paddings
=
param
.
Paddings
();
std
::
vector
<
int
>
dilations
=
param
.
Dilations
();
std
::
vector
<
int
>
dilations
=
param
.
Dilations
();
DLOG
<<
" compute end get Attrs "
<<
strides
[
0
];
//
DLOG << " compute end get Attrs " << strides[0];
const
int
batch_size
=
static_cast
<
int
>
(
input
->
dims
()[
0
]);
const
int
batch_size
=
static_cast
<
int
>
(
input
->
dims
()[
0
]);
std
::
vector
<
int64_t
>
filter_shape_vec
(
framework
::
vectorize
(
filter
.
dims
()));
std
::
vector
<
int64_t
>
filter_shape_vec
(
framework
::
vectorize
(
filter
.
dims
()));
std
::
vector
<
int64_t
>
output_shape_vec
(
framework
::
vectorize
(
output
->
dims
()));
std
::
vector
<
int64_t
>
output_shape_vec
(
framework
::
vectorize
(
output
->
dims
()));
size_t
data_dim
=
filter_shape_vec
.
size
()
-
2
;
size_t
data_dim
=
filter_shape_vec
.
size
()
-
2
;
std
::
vector
<
int64_t
>
col_shape_vec
(
1
+
2
*
data_dim
);
std
::
vector
<
int64_t
>
col_shape_vec
(
1
+
2
*
data_dim
);
col_shape_vec
[
0
]
=
input
->
dims
()[
1
]
/
groups
;
col_shape_vec
[
0
]
=
input
->
dims
()[
1
]
/
groups
;
...
@@ -71,8 +71,6 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
...
@@ -71,8 +71,6 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
col_matrix
.
ShareDataWith
(
col
);
col_matrix
.
ShareDataWith
(
col
);
col_matrix
.
Resize
(
col_matrix_shape
);
col_matrix
.
Resize
(
col_matrix_shape
);
}
}
DLOG
<<
" col_shape = "
<<
col_shape
;
DLOG
<<
" col_matrix_shape = "
<<
col_matrix_shape
;
framework
::
DDim
input_shape
=
framework
::
slice_ddim
(
framework
::
DDim
input_shape
=
framework
::
slice_ddim
(
input
->
dims
(),
1
,
static_cast
<
int
>
(
input
->
dims
().
size
()));
input
->
dims
(),
1
,
static_cast
<
int
>
(
input
->
dims
().
size
()));
...
@@ -80,8 +78,6 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
...
@@ -80,8 +78,6 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
framework
::
DDim
filter_matrix_shape
=
{
filter
.
dims
()[
0
],
framework
::
DDim
filter_matrix_shape
=
{
filter
.
dims
()[
0
],
filter
.
numel
()
/
filter
.
dims
()[
0
]};
filter
.
numel
()
/
filter
.
dims
()[
0
]};
filter
.
Resize
(
filter_matrix_shape
);
filter
.
Resize
(
filter_matrix_shape
);
DLOG
<<
" filter.deims() = "
<<
filter
.
dims
();
framework
::
DDim
output_matrix_shape
=
{
framework
::
DDim
output_matrix_shape
=
{
output
->
dims
()[
1
],
output
->
dims
()[
1
],
output
->
numel
()
/
(
output
->
dims
()[
0
]
*
output
->
dims
()[
1
])};
output
->
numel
()
/
(
output
->
dims
()[
0
]
*
output
->
dims
()[
1
])};
...
@@ -118,9 +114,6 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
...
@@ -118,9 +114,6 @@ void ConvKernel<CPU, float>::Compute(const ConvParam ¶m) const {
// gemm
// gemm
Tensor
out_slice
=
out_batch
.
Slice
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
Tensor
out_slice
=
out_batch
.
Slice
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
Tensor
filter_slice
=
filter
.
Slice
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
Tensor
filter_slice
=
filter
.
Slice
(
g
*
out_step
,
(
g
+
1
)
*
out_step
);
DLOG
<<
" out_slice "
<<
out_slice
.
dims
();
DLOG
<<
" filter_slice "
<<
filter_slice
.
dims
();
DLOG
<<
" col_matrix "
<<
col_matrix
.
dims
();
math
::
matmul
<
float
>
(
filter_slice
,
false
,
col_matrix
,
false
,
math
::
matmul
<
float
>
(
filter_slice
,
false
,
col_matrix
,
false
,
static_cast
<
float
>
(
1
),
&
out_slice
,
static_cast
<
float
>
(
1
),
&
out_slice
,
static_cast
<
float
>
(
0
));
static_cast
<
float
>
(
0
));
...
...
test/executor_for_test.h
浏览文件 @
88c8a6d7
...
@@ -77,13 +77,13 @@ class Executor4Test : public Executor<DeviceType> {
...
@@ -77,13 +77,13 @@ class Executor4Test : public Executor<DeviceType> {
const
DDim
&
dDim
)
{
const
DDim
&
dDim
)
{
auto
scope
=
this
->
program_
.
scope
;
auto
scope
=
this
->
program_
.
scope
;
Variable
*
g_feed_value
=
scope
->
Var
(
input
);
Variable
*
g_feed_value
=
scope
->
Var
(
input
);
auto
tensor
=
g_feed_value
->
GetMutable
<
Tensor
>
();
auto
tensor
=
g_feed_value
->
GetMutable
<
LoD
Tensor
>
();
tensor
->
ShareDataWith
(
t
);
tensor
->
ShareDataWith
(
t
);
Variable
*
con_output
=
scope
->
Var
(
output
);
Variable
*
con_output
=
scope
->
Var
(
output
);
auto
*
output_tensor
=
con_output
->
GetMutable
<
Tensor
>
();
auto
*
output_tensor
=
con_output
->
GetMutable
<
LoD
Tensor
>
();
output_tensor
->
mutable_data
<
float
>
(
dDim
);
output_tensor
->
mutable_data
<
float
>
(
dDim
);
std
::
shared_ptr
<
Tensor
>
out_tensor
=
std
::
make_shared
<
LoDTensor
>
();
std
::
shared_ptr
<
LoD
Tensor
>
out_tensor
=
std
::
make_shared
<
LoDTensor
>
();
out_tensor
.
reset
(
output_tensor
);
out_tensor
.
reset
(
output_tensor
);
std
::
shared_ptr
<
paddle_mobile
::
framework
::
BlockDesc
>
to_predict_block
=
std
::
shared_ptr
<
paddle_mobile
::
framework
::
BlockDesc
>
to_predict_block
=
...
...
test/operators/test_sigmoid_op.cpp
浏览文件 @
88c8a6d7
...
@@ -19,16 +19,12 @@ limitations under the License. */
...
@@ -19,16 +19,12 @@ limitations under the License. */
int
main
()
{
int
main
()
{
paddle_mobile
::
framework
::
Tensor
input
;
paddle_mobile
::
framework
::
Tensor
input
;
paddle_mobile
::
framework
::
Tensor
output
;
paddle_mobile
::
framework
::
Tensor
output
;
DLOG
<<
1
;
SetupTensor
<
float
>
(
&
input
,
{
1
,
4
,
60
,
60
},
static_cast
<
float
>
(
0
),
SetupTensor
<
float
>
(
&
input
,
{
1
,
4
,
60
,
60
},
static_cast
<
float
>
(
0
),
static_cast
<
float
>
(
1
));
static_cast
<
float
>
(
1
));
DLOG
<<
2
;
auto
out_ddim
=
paddle_mobile
::
framework
::
make_ddim
({
1
,
4
,
60
,
60
});
auto
out_ddim
=
paddle_mobile
::
framework
::
make_ddim
({
1
,
4
,
60
,
60
});
output
.
Resize
(
out_ddim
);
output
.
Resize
(
out_ddim
);
DLOG
<<
3
;
paddle_mobile
::
operators
::
sigmoid
(
&
input
,
&
output
);
paddle_mobile
::
operators
::
sigmoid
(
&
input
,
&
output
);
DLOG
<<
4
;
auto
*
output_ptr
=
output
.
data
<
float
>
();
auto
*
output_ptr
=
output
.
data
<
float
>
();
for
(
int
j
=
0
;
j
<
output
.
numel
();
++
j
)
{
for
(
int
j
=
0
;
j
<
output
.
numel
();
++
j
)
{
DLOG
<<
" value of output: "
<<
output_ptr
[
j
];
DLOG
<<
" value of output: "
<<
output_ptr
[
j
];
...
...
test/operators/test_softmax_op.cpp
浏览文件 @
88c8a6d7
...
@@ -18,7 +18,7 @@ limitations under the License. */
...
@@ -18,7 +18,7 @@ limitations under the License. */
int
main
()
{
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
auto
program
=
loader
.
Load
(
std
::
string
(
"models/mobilenet"
));
auto
program
=
loader
.
Load
(
std
::
string
(
"
../
models/mobilenet"
));
if
(
program
.
originProgram
==
nullptr
)
{
if
(
program
.
originProgram
==
nullptr
)
{
DLOG
<<
"program read file"
;
DLOG
<<
"program read file"
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录