Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
22a62842
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
22a62842
编写于
5月 18, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean unit test folder
上级
79afa574
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
142 addition
and
36 deletion
+142
-36
.gitignore
.gitignore
+2
-0
CMakeLists.txt
CMakeLists.txt
+1
-9
src/framework/operator.h
src/framework/operator.h
+11
-1
src/io.cpp
src/io.cpp
+14
-22
test/CMakeLists.txt
test/CMakeLists.txt
+16
-0
test/common/test_log.cpp
test/common/test_log.cpp
+4
-3
test/framework/test_load.cpp
test/framework/test_load.cpp
+28
-0
test/main.cpp
test/main.cpp
+2
-1
test/operators/test_cov_op.cpp
test/operators/test_cov_op.cpp
+64
-0
未找到文件。
.gitignore
浏览文件 @
22a62842
...
...
@@ -54,3 +54,5 @@ paddle-mobile.cbp
cmake-build-debug/
test/models/
\ No newline at end of file
CMakeLists.txt
浏览文件 @
22a62842
...
...
@@ -45,12 +45,4 @@ ADD_LIBRARY(paddle-mobile-static STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
target_link_libraries
(
paddle-mobile-static protobuf-lite openblas
)
#add_dependencies(paddle-mobile openblas_proj)
# gen test
ADD_EXECUTABLE
(
paddle-mobile-test test/main.cpp test/test_helper.h
test/elementwise_add_op_test.h test/test_include.h
test/mul_op_test.h
)
target_link_libraries
(
paddle-mobile-test paddle-mobile
)
# gen test log
ADD_EXECUTABLE
(
test-log test/unit-test/test_log.cpp
)
target_link_libraries
(
test-log paddle-mobile
)
add_subdirectory
(
test
)
\ No newline at end of file
src/framework/operator.h
浏览文件 @
22a62842
...
...
@@ -18,6 +18,8 @@ SOFTWARE.
#pragma once
#include <map>
#include "attribute.h"
#include "block_desc.h"
#include "common/type_define.h"
...
...
@@ -29,10 +31,18 @@ SOFTWARE.
#include "scope.h"
#include "tensor.h"
#include "variable.h"
#include <map>
namespace
paddle_mobile
{
namespace
framework
{
static
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
op_input_output_key
=
{
{
"conv2d"
,
{
"Input"
,
"Output"
}},
{
"relu"
,
{
"X"
,
"Out"
}},
{
"softmax"
,
{
"X"
,
"Out"
}},
{
"mul"
,
{
"X"
,
"Out"
}},
{
"elementwise_add"
,
{
"X"
,
"Out"
}},
{
"pool2d"
,
{
"X"
,
"Out"
}},
{
"batch_norm"
,
{
"X"
,
"Y"
}},
{
"lrn"
,
{
"X"
,
"Out"
}},
{
"concat"
,
{
"X"
,
"Out"
}},
};
template
<
typename
Dtype
>
class
OperatorBase
:
PaddleMobileObject
{
public:
...
...
src/io.cpp
浏览文件 @
22a62842
...
...
@@ -17,7 +17,6 @@ SOFTWARE.
==============================================================================*/
#include <fstream>
#include <iostream>
#include "common/log.h"
#include "framework/framework.pb.h"
...
...
@@ -42,27 +41,26 @@ namespace paddle_mobile {
template
<
typename
Dtype
,
Precision
P
>
void
Loader
<
Dtype
,
P
>::
LoadVar
(
framework
::
LoDTensor
*
tensor
,
const
std
::
string
&
file_path
)
{
LOG
(
kLOG_DEBUG
)
<<
" to load "
<<
file_path
;
// LOG(kLOG_DEBUG) << " to load " << file_path;
// Log(kLOG_DEBUG) << "123";
std
::
ifstream
is
(
file_path
);
std
::
streampos
pos
=
is
.
tellg
();
// save current position
is
.
seekg
(
0
,
std
::
ios
::
end
);
LOG
(
kLOG_DEBUG
)
<<
" file length = "
<<
is
.
tellg
();
//
LOG(kLOG_DEBUG) << " file length = " << is.tellg();
is
.
seekg
(
pos
);
// restore saved position
// 1. version
uint32_t
version
;
is
.
read
(
reinterpret_cast
<
char
*>
(
&
version
),
sizeof
(
version
));
LOG
(
kLOG_INFO
)
<<
" version: "
<<
version
;
//
LOG(kLOG_INFO) << " version: " << version;
// 2 Lod information
uint64_t
lod_level
;
is
.
read
(
reinterpret_cast
<
char
*>
(
&
lod_level
),
sizeof
(
lod_level
));
LOG
(
kLOG_DEBUG
)
<<
" load level: "
<<
lod_level
;
LOG
(
kLOG_DEBUG
)
<<
" lod info: "
;
//
LOG(kLOG_DEBUG) << " load level: " << lod_level;
//
LOG(kLOG_DEBUG) << " lod info: ";
auto
&
lod
=
*
tensor
->
mutable_lod
();
lod
.
resize
(
lod_level
);
for
(
uint64_t
i
=
0
;
i
<
lod_level
;
++
i
)
{
...
...
@@ -197,32 +195,26 @@ namespace paddle_mobile {
#ifdef PADDLE_MOBILE_DEBUG
for
(
int
i
=
0
;
i
<
program_desc_proto
.
blocks
().
size
();
++
i
)
{
framework
::
proto
::
BlockDesc
block
=
program_desc_proto
.
blocks
()[
i
];
// std::cout << "block: " << block.idx() << std::endl
;
LOG
(
kLOG_DEBUG
)
<<
"block: "
<<
block
.
idx
()
;
for
(
int
j
=
0
;
j
<
block
.
ops
().
size
();
++
j
)
{
framework
::
proto
::
OpDesc
op
=
block
.
ops
()[
j
];
// std::cout << " op: " << op.type() << std::endl;
LOG
(
kLOG_DEBUG1
)
<<
" op: "
<<
op
.
type
();
for
(
int
m
=
0
;
m
<
op
.
inputs_size
();
++
m
)
{
const
framework
::
proto
::
OpDesc
::
Var
&
var
=
op
.
inputs
(
m
);
// std::cout << " input parameter: " <<
// var.parameter() <<
// std::endl;
LOG
(
kLOG_DEBUG2
)
<<
" input parameter: "
<<
var
.
parameter
();
for
(
int
n
=
0
;
n
<
var
.
arguments
().
size
();
++
n
)
{
// std::cout << " argument - " <<
// var.arguments()[n] <<
// std::endl;
LOG
(
kLOG_DEBUG3
)
<<
" argument - "
<<
var
.
arguments
()[
n
];
}
}
for
(
int
y
=
0
;
y
<
op
.
outputs_size
();
++
y
)
{
const
framework
::
proto
::
OpDesc
::
Var
&
var
=
op
.
outputs
(
y
);
// std::cout << " output parameter: " <<
// var.parameter() <<
// std::endl;
LOG
(
kLOG_DEBUG2
)
<<
" out parameter: "
<<
var
.
parameter
();
for
(
int
z
=
0
;
z
<
var
.
arguments
().
size
();
++
z
)
{
// std::cout << " argument - " <<
// var.arguments()[z] <<
// std::endl;
LOG
(
kLOG_DEBUG3
)
<<
" argument - "
<<
var
.
arguments
()[
z
];
}
}
...
...
test/CMakeLists.txt
0 → 100644
浏览文件 @
22a62842
# gen test
ADD_EXECUTABLE
(
paddle-mobile-test main.cpp test_helper.h elementwise_add_op_test.h test_include.h mul_op_test.h
)
target_link_libraries
(
paddle-mobile-test paddle-mobile
)
# gen test
ADD_EXECUTABLE
(
test-conv-op operators/test_cov_op.cpp test_helper.h test_include.h
)
target_link_libraries
(
test-conv-op paddle-mobile
)
# gen test log
ADD_EXECUTABLE
(
test-log common/test_log.cpp
)
target_link_libraries
(
test-log paddle-mobile
)
# gen test log
ADD_EXECUTABLE
(
test-load framework/test_load.cpp
)
target_link_libraries
(
test-load paddle-mobile
)
\ No newline at end of file
test/
unit-test
/test_log.cpp
→
test/
common
/test_log.cpp
浏览文件 @
22a62842
...
...
@@ -19,18 +19,19 @@ SOFTWARE.
#include "common/log.h"
int
main
()
{
DLOGF
(
"DASJFDAFJ%d -- %f"
,
12345
,
344.234
);
LOGF
(
paddle_mobile
::
kLOG_DEBUG
,
"DASJFDAFJ%d -- %f"
,
12345
,
344.234
);
LOG
(
paddle_mobile
::
kLOG_DEBUG
)
<<
"test debug"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
"test debug1"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG2
)
<<
"test debug2"
<<
" next log"
;
DLOG
<<
"test DLOG"
;
LOG
(
paddle_mobile
::
kLOG_ERROR
)
<<
" error occur !"
;
return
0
;
...
...
test/framework/test_load.cpp
0 → 100644
浏览文件 @
22a62842
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#include "io.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
//../../../test/models/googlenet
//../../../test/models/mobilenet
auto
program
=
loader
.
Load
(
std
::
string
(
"../../../test/models/mobilenet"
));
return
0
;
}
\ No newline at end of file
test/main.cpp
浏览文件 @
22a62842
...
...
@@ -17,9 +17,9 @@ SOFTWARE.
==============================================================================*/
#include "elementwise_add_op_test.h"
#include "mul_op_test.h"
#include "framework/executor.h"
#include "io.h"
#include "mul_op_test.h"
#include "test_helper.h"
//
...
...
@@ -38,6 +38,7 @@ SOFTWARE.
//}
int
main
()
{
std
::
string
data_set
=
"cifar10"
;
//
// if (data_set == "cifar10") {
...
...
test/operators/test_cov_op.cpp
0 → 100644
浏览文件 @
22a62842
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#include "../test_helper.h"
#include "framework/executor.h"
#include "io.h"
int
main
()
{
std
::
string
data_set
=
"cifar10"
;
//
// if (data_set == "cifar10") {
// SetupTensor<float>(&input, {FLAGS_batch_size, 3, 32, 32},
// static_cast<float>(0), static_cast<float>(1));
// } else if (data_set == "imagenet") {
// SetupTensor<float>(&input, {FLAGS_batch_size, 3, 224, 224},
// static_cast<float>(0), static_cast<float>(1));
// } else {
// LOG(FATAL) << "Only cifar10 or imagenet is supported.";
// }
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
auto
program
=
loader
.
Load
(
std
::
string
(
"../../../test/models/googlenet"
));
paddle_mobile
::
framework
::
Executor
<
paddle_mobile
::
CPU
>
executor
(
program
);
paddle_mobile
::
framework
::
Tensor
input
;
SetupTensor
<
float
>
(
&
input
,
{
1
,
3
,
32
,
32
},
static_cast
<
float
>
(
0
),
static_cast
<
float
>
(
1
));
float
*
input_ptr
=
input
.
data
<
float
>
();
for
(
int
i
=
0
;
i
<
input
.
numel
();
++
i
)
{
// std::cout << input_ptr[i] << std::endl;
}
// std::cout << "input: " << input.memory_size() << std::endl;
// std::cout << "input: " << input.numel() << std::endl;
auto
output
=
executor
.
predict
(
input
);
// std::cout << "output: " << output->memory_size() << std::endl;
// std::cout << "output: " << output->numel() << std::endl;
// float* output_ptr = output->data<float>();
// for (int j = 0; j < output->numel(); ++j) {
// std::cout << " value of output: " << output_ptr[j] << std::endl;
//
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录