Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b1869f16
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b1869f16
编写于
2月 08, 2018
作者:
Y
Yiqun Liu
提交者:
GitHub
2月 08, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify the inference unittests' cmake and codes. (#8216)
上级
47c13508
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
36 addition
and
87 deletion
+36
-87
paddle/inference/tests/book/CMakeLists.txt
paddle/inference/tests/book/CMakeLists.txt
+29
-25
paddle/inference/tests/book/test_helper.h
paddle/inference/tests/book/test_helper.h
+1
-0
paddle/inference/tests/book/test_inference_image_classification.cc
...ference/tests/book/test_inference_image_classification.cc
+6
-58
paddle/inference/tests/book/test_inference_label_semantic_roles.cc
...ference/tests/book/test_inference_label_semantic_roles.cc
+0
-2
paddle/inference/tests/book/test_inference_recognize_digits.cc
...e/inference/tests/book/test_inference_recognize_digits.cc
+0
-2
python/paddle/v2/fluid/tests/book/test_image_classification.py
...n/paddle/v2/fluid/tests/book/test_image_classification.py
+0
-0
未找到文件。
paddle/inference/tests/book/CMakeLists.txt
浏览文件 @
b1869f16
set
(
PYTHON_TESTS_DIR
${
PADDLE_SOURCE_DIR
}
/python/paddle/v2/fluid/tests
)
function
(
inference_test TARGET_NAME
)
cc_test
(
test_inference_recognize_digits_mlp
set
(
options
""
)
SRCS test_inference_recognize_digits.cc
set
(
oneValueArgs
""
)
set
(
multiValueArgs ARGS
)
cmake_parse_arguments
(
inference_test
"
${
options
}
"
"
${
oneValueArgs
}
"
"
${
multiValueArgs
}
"
${
ARGN
}
)
set
(
PYTHON_TESTS_DIR
${
PADDLE_SOURCE_DIR
}
/python/paddle/v2/fluid/tests
)
if
(
inference_test_ARGS
)
foreach
(
arg
${
inference_test_ARGS
}
)
cc_test
(
test_inference_
${
TARGET_NAME
}
_
${
arg
}
SRCS test_inference_
${
TARGET_NAME
}
.cc
DEPS ARCHIVE_START paddle_fluid ARCHIVE_END
DEPS ARCHIVE_START paddle_fluid ARCHIVE_END
ARGS --dirname=
${
PYTHON_TESTS_DIR
}
/book/recognize_digits_mlp.inference.model
)
ARGS --dirname=
${
PYTHON_TESTS_DIR
}
/book/
${
TARGET_NAME
}
_
${
arg
}
.inference.model
)
cc_test
(
test_inference_image_classification_vgg
set_tests_properties
(
test_inference_
${
TARGET_NAME
}
_
${
arg
}
SRCS test_inference_image_classification.cc
PROPERTIES DEPENDS test_
${
TARGET_NAME
}
)
endforeach
()
else
()
cc_test
(
test_inference_
${
TARGET_NAME
}
SRCS test_inference_
${
TARGET_NAME
}
.cc
DEPS ARCHIVE_START paddle_fluid ARCHIVE_END
DEPS ARCHIVE_START paddle_fluid ARCHIVE_END
ARGS --dirname=
${
PYTHON_TESTS_DIR
}
/book/image_classification_vgg.inference.model
)
ARGS --dirname=
${
PYTHON_TESTS_DIR
}
/book/
${
TARGET_NAME
}
.inference.model
)
cc_test
(
test_inference_image_classification_resnet
set_tests_properties
(
test_inference_
${
TARGET_NAME
}
SRCS test_inference_image_classification.cc
PROPERTIES DEPENDS test_
${
TARGET_NAME
}
)
DEPS ARCHIVE_START paddle_fluid ARCHIVE_END
endif
()
ARGS --dirname=
${
PYTHON_TESTS_DIR
}
/book/image_classification_resnet.inference.model
)
endfunction
(
inference_test
)
cc_test
(
test_inference_label_semantic_roles
SRCS test_inference_label_semantic_roles.cc
inference_test
(
recognize_digits ARGS mlp
)
DEPS ARCHIVE_START paddle_fluid ARCHIVE_END
inference_test
(
image_classification ARGS vgg resnet
)
ARGS --dirname=
${
PYTHON_TESTS_DIR
}
/book/label_semantic_roles.inference.model
)
inference_test
(
label_semantic_roles
)
set_tests_properties
(
test_inference_recognize_digits_mlp
PROPERTIES DEPENDS test_recognize_digits
)
set_tests_properties
(
test_inference_image_classification_vgg
PROPERTIES DEPENDS test_image_classification_train
)
set_tests_properties
(
test_inference_image_classification_resnet
PROPERTIES DEPENDS test_image_classification_train
)
set_tests_properties
(
test_inference_label_semantic_roles
PROPERTIES DEPENDS test_label_semantic_roles
)
paddle/inference/tests/book/test_helper.h
浏览文件 @
b1869f16
...
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <time.h>
#include "paddle/framework/lod_tensor.h"
#include "paddle/framework/lod_tensor.h"
#include "paddle/inference/io.h"
#include "paddle/inference/io.h"
...
...
paddle/inference/tests/book/test_inference_image_classification.cc
浏览文件 @
b1869f16
...
@@ -13,51 +13,11 @@ See the License for the specific language governing permissions and
...
@@ -13,51 +13,11 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <time.h>
#include <sstream>
#include "gflags/gflags.h"
#include "gflags/gflags.h"
#include "paddle/framework/lod_tensor.h"
#include "test_helper.h"
#include "paddle/inference/io.h"
DEFINE_string
(
dirname
,
""
,
"Directory of the inference model."
);
DEFINE_string
(
dirname
,
""
,
"Directory of the inference model."
);
template
<
typename
Place
,
typename
T
>
void
TestInference
(
const
std
::
string
&
dirname
,
const
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>&
cpu_feeds
,
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>&
cpu_fetchs
)
{
// 1. Define place, executor and scope
auto
place
=
Place
();
auto
executor
=
paddle
::
framework
::
Executor
(
place
);
auto
*
scope
=
new
paddle
::
framework
::
Scope
();
// 2. Initialize the inference_program and load all parameters from file
auto
inference_program
=
paddle
::
inference
::
Load
(
executor
,
*
scope
,
dirname
);
// 3. Get the feed_target_names and fetch_target_names
const
std
::
vector
<
std
::
string
>&
feed_target_names
=
inference_program
->
GetFeedTargetNames
();
const
std
::
vector
<
std
::
string
>&
fetch_target_names
=
inference_program
->
GetFetchTargetNames
();
// 4. Prepare inputs: set up maps for feed targets
std
::
map
<
std
::
string
,
const
paddle
::
framework
::
LoDTensor
*>
feed_targets
;
for
(
size_t
i
=
0
;
i
<
feed_target_names
.
size
();
++
i
)
{
// Please make sure that cpu_feeds[i] is right for feed_target_names[i]
feed_targets
[
feed_target_names
[
i
]]
=
cpu_feeds
[
i
];
}
// 5. Define Tensor to get the outputs: set up maps for fetch targets
std
::
map
<
std
::
string
,
paddle
::
framework
::
LoDTensor
*>
fetch_targets
;
for
(
size_t
i
=
0
;
i
<
fetch_target_names
.
size
();
++
i
)
{
fetch_targets
[
fetch_target_names
[
i
]]
=
cpu_fetchs
[
i
];
}
// 6. Run the inference program
executor
.
Run
(
*
inference_program
,
scope
,
feed_targets
,
fetch_targets
);
delete
scope
;
}
TEST
(
inference
,
image_classification
)
{
TEST
(
inference
,
image_classification
)
{
if
(
FLAGS_dirname
.
empty
())
{
if
(
FLAGS_dirname
.
empty
())
{
LOG
(
FATAL
)
<<
"Usage: ./example --dirname=path/to/your/model"
;
LOG
(
FATAL
)
<<
"Usage: ./example --dirname=path/to/your/model"
;
...
@@ -70,12 +30,10 @@ TEST(inference, image_classification) {
...
@@ -70,12 +30,10 @@ TEST(inference, image_classification) {
// In unittests, this is done in paddle/testing/paddle_gtest_main.cc
// In unittests, this is done in paddle/testing/paddle_gtest_main.cc
paddle
::
framework
::
LoDTensor
input
;
paddle
::
framework
::
LoDTensor
input
;
srand
(
time
(
0
));
// Use normilized image pixels as input data,
float
*
input_ptr
=
// which should be in the range [0.0, 1.0].
input
.
mutable_data
<
float
>
({
1
,
3
,
32
,
32
},
paddle
::
platform
::
CPUPlace
());
SetupTensor
<
float
>
(
for
(
int
i
=
0
;
i
<
3072
;
++
i
)
{
input
,
{
1
,
3
,
32
,
32
},
static_cast
<
float
>
(
0
),
static_cast
<
float
>
(
1
));
input_ptr
[
i
]
=
rand
()
/
(
static_cast
<
float
>
(
RAND_MAX
));
}
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>
cpu_feeds
;
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>
cpu_feeds
;
cpu_feeds
.
push_back
(
&
input
);
cpu_feeds
.
push_back
(
&
input
);
...
@@ -98,16 +56,6 @@ TEST(inference, image_classification) {
...
@@ -98,16 +56,6 @@ TEST(inference, image_classification) {
dirname
,
cpu_feeds
,
cpu_fetchs2
);
dirname
,
cpu_feeds
,
cpu_fetchs2
);
LOG
(
INFO
)
<<
output2
.
dims
();
LOG
(
INFO
)
<<
output2
.
dims
();
EXPECT_EQ
(
output1
.
dims
(),
output2
.
dims
());
CheckError
<
float
>
(
output1
,
output2
);
EXPECT_EQ
(
output1
.
numel
(),
output2
.
numel
());
float
err
=
1E-3
;
int
count
=
0
;
for
(
int64_t
i
=
0
;
i
<
output1
.
numel
();
++
i
)
{
if
(
fabs
(
output1
.
data
<
float
>
()[
i
]
-
output2
.
data
<
float
>
()[
i
])
>
err
)
{
count
++
;
}
}
EXPECT_EQ
(
count
,
0
)
<<
"There are "
<<
count
<<
" different elements."
;
#endif
#endif
}
}
paddle/inference/tests/book/test_inference_label_semantic_roles.cc
浏览文件 @
b1869f16
...
@@ -13,8 +13,6 @@ See the License for the specific language governing permissions and
...
@@ -13,8 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <time.h>
#include <sstream>
#include "gflags/gflags.h"
#include "gflags/gflags.h"
#include "test_helper.h"
#include "test_helper.h"
...
...
paddle/inference/tests/book/test_inference_recognize_digits.cc
浏览文件 @
b1869f16
...
@@ -13,8 +13,6 @@ See the License for the specific language governing permissions and
...
@@ -13,8 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <time.h>
#include <sstream>
#include "gflags/gflags.h"
#include "gflags/gflags.h"
#include "test_helper.h"
#include "test_helper.h"
...
...
python/paddle/v2/fluid/tests/book/test_image_classification
_train
.py
→
python/paddle/v2/fluid/tests/book/test_image_classification.py
浏览文件 @
b1869f16
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录