Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
e01b0941
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e01b0941
编写于
11月 17, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove test_CompareTwoOpts
上级
c1931468
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
0 addition
and
282 deletion
+0
-282
paddle/trainer/tests/CMakeLists.txt
paddle/trainer/tests/CMakeLists.txt
+0
-10
paddle/trainer/tests/sample_trainer_config_opt_a.conf
paddle/trainer/tests/sample_trainer_config_opt_a.conf
+0
-44
paddle/trainer/tests/sample_trainer_config_opt_b.conf
paddle/trainer/tests/sample_trainer_config_opt_b.conf
+0
-44
paddle/trainer/tests/test_CompareTwoOpts.cpp
paddle/trainer/tests/test_CompareTwoOpts.cpp
+0
-184
未找到文件。
paddle/trainer/tests/CMakeLists.txt
浏览文件 @
e01b0941
...
...
@@ -29,16 +29,6 @@ if(WITH_PYTHON)
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle/
)
endif
()
############### test_CompareTwoOpts ###################
add_unittest_without_exec
(
test_CompareTwoOpts
test_CompareTwoOpts.cpp
)
add_test
(
NAME test_CompareTwoOpts
COMMAND
${
PADDLE_SOURCE_DIR
}
/paddle/.set_python_path.sh -d
${
PADDLE_SOURCE_DIR
}
/python/
${
CMAKE_CURRENT_BINARY_DIR
}
/test_CompareTwoOpts
--config_file_a=trainer/tests/sample_trainer_config_opt_a.conf --config_file_b=trainer/tests/sample_trainer_config_opt_b.conf
--num_passes=1 --need_high_accuracy=0
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle/
)
################# test_recurrent_machine_generation ###############
add_unittest_without_exec
(
test_recurrent_machine_generation
test_recurrent_machine_generation.cpp
)
...
...
paddle/trainer/tests/sample_trainer_config_opt_a.conf
已删除
100644 → 0
浏览文件 @
c1931468
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle
.
trainer_config_helpers
import
*
################################### Data Configuration ###################################
TrainData
(
SimpleData
(
files
=
"trainer/tests/sample_filelist.txt"
,
feat_dim
=
3
,
context_len
=
0
,
buffer_capacity
=
1000000
))
################################### Algorithm Configuration ###################################
settings
(
batch_size
=
1000
,
learning_method
=
MomentumOptimizer
(
momentum
=
0
.
5
,
sparse
=
False
))
################################### Network Configuration ###################################
data
=
data_layer
(
name
=
"input"
,
size
=
3
)
fc1
=
fc_layer
(
input
=
data
,
size
=
800
,
bias_attr
=
True
,
act
=
SigmoidActivation
())
fc2
=
fc_layer
(
input
=
fc1
,
size
=
800
,
bias_attr
=
True
,
act
=
SigmoidActivation
())
output
=
fc_layer
(
input
=[
fc1
,
fc2
],
size
=
10
,
bias_attr
=
True
,
act
=
SoftmaxActivation
())
lbl
=
data_layer
(
name
=
"label"
,
size
=
1
)
cost
=
classification_cost
(
input
=
output
,
label
=
lbl
)
outputs
(
cost
)
paddle/trainer/tests/sample_trainer_config_opt_b.conf
已删除
100644 → 0
浏览文件 @
c1931468
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle
.
trainer_config_helpers
import
*
################################### Data Configuration ###################################
TrainData
(
SimpleData
(
files
=
"trainer/tests/sample_filelist.txt"
,
feat_dim
=
3
,
context_len
=
0
,
buffer_capacity
=
1000000
))
################################### Algorithm Configuration ###################################
settings
(
batch_size
=
1000
,
learning_method
=
MomentumOptimizer
(
momentum
=
0
.
5
,
sparse
=
False
))
################################### Network Configuration ###################################
data
=
data_layer
(
name
=
"input"
,
size
=
3
)
fc1
=
fc_layer
(
input
=
data
,
size
=
800
,
bias_attr
=
True
,
act
=
SigmoidActivation
())
fc2
=
fc_layer
(
input
=
fc1
,
size
=
800
,
bias_attr
=
True
,
act
=
SigmoidActivation
())
output
=
fc_layer
(
input
=[
fc1
,
fc2
],
size
=
10
,
bias_attr
=
True
,
act
=
SoftmaxActivation
())
lbl
=
data_layer
(
name
=
"label"
,
size
=
1
)
cost
=
classification_cost
(
input
=
output
,
label
=
lbl
)
outputs
(
cost
)
paddle/trainer/tests/test_CompareTwoOpts.cpp
已删除
100644 → 0
浏览文件 @
c1931468
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include <paddle/utils/PythonUtil.h>
#include <algorithm>
#include <cstdlib>
#include "paddle/trainer/Trainer.h"
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
DECLARE_int32
(
gpu_id
);
DECLARE_bool
(
local
);
DECLARE_bool
(
use_gpu
);
DECLARE_string
(
config
);
DECLARE_string
(
nics
);
DEFINE_string
(
config_file_a
,
""
,
"config of one network to compare"
);
DEFINE_string
(
config_file_b
,
""
,
"config of another network to compare"
);
DEFINE_bool
(
need_high_accuracy
,
true
,
"whether need to run in double accuracy (recommended)"
);
DEFINE_double
(
max_diff_ratio
,
0.0
f
,
"max diff ratio allowed for outputs and parameters (value/gradient)"
);
struct
ComData
{
vector
<
Argument
>
outArgs
;
vector
<
ParameterPtr
>
parameters
;
};
void
calcGradient
(
ComData
&
data
,
const
string
configFile
)
{
FLAGS_config
=
configFile
;
FLAGS_local
=
true
;
FLAGS_use_gpu
=
false
;
FLAGS_nics
=
""
;
*
ThreadLocalRand
::
getSeed
()
=
0
;
srand
(
0
);
Trainer
trainer
;
trainer
.
init
(
TrainerConfigHelper
::
createFromFlagConfig
(),
false
);
data
.
parameters
=
trainer
.
getGradientMachine
()
->
getParameters
();
trainer
.
getDataProvider
()
->
setSkipShuffle
();
trainer
.
train
();
}
void
checkBuffer
(
real
*
A
,
const
char
*
desA
,
real
*
B
,
const
char
*
desB
,
size_t
len
,
size_t
width
=
1
)
{
int
nNum
=
0
;
for
(
size_t
i
=
0
;
i
<
len
;
++
i
)
{
real
diff
=
fabs
(
A
[
i
]
-
B
[
i
]);
if
(
diff
>
0.0
f
&&
diff
/
std
::
max
(
fabs
(
A
[
i
]),
fabs
(
B
[
i
]))
>
FLAGS_max_diff_ratio
)
{
nNum
++
;
LOG
(
INFO
)
<<
"Row: "
<<
i
/
width
<<
", "
<<
desA
<<
" : "
<<
A
[
i
]
<<
" "
<<
desB
<<
" : "
<<
B
[
i
];
}
}
EXPECT_EQ
(
0
,
nNum
);
LOG
(
INFO
)
<<
"
\n\n
"
;
}
void
compareGradient
(
ComData
&
comDataA
,
ComData
&
comDataB
)
{
vector
<
Argument
>
outArgsA
=
comDataA
.
outArgs
;
vector
<
Argument
>
outArgsB
=
comDataB
.
outArgs
;
for
(
size_t
i
=
0
;
i
<
outArgsA
.
size
();
++
i
)
{
CpuMatrix
matA
(
outArgsA
[
i
].
value
->
getHeight
(),
outArgsA
[
i
].
value
->
getWidth
());
CpuMatrix
matB
(
outArgsB
[
i
].
value
->
getHeight
(),
outArgsB
[
i
].
value
->
getWidth
());
matA
.
copyFrom
(
*
outArgsA
[
i
].
value
);
matB
.
copyFrom
(
*
outArgsB
[
i
].
value
);
LOG
(
INFO
)
<<
"
\n
--------------------------------"
<<
" Check Network Output_"
<<
i
<<
":"
<<
" -------------------------------------
\n
"
;
checkBuffer
(
matA
.
getData
(),
"network A output"
,
matB
.
getData
(),
"network B output"
,
matA
.
getElementCnt
(),
matA
.
getWidth
());
}
vector
<
ParameterPtr
>&
parametersA
=
comDataA
.
parameters
;
vector
<
ParameterPtr
>&
parametersB
=
comDataB
.
parameters
;
LOG
(
INFO
)
<<
"
\n\n
--------------------------------"
<<
" Check Gradient Machine Parameters:"
<<
" -------------------------------------
\n
"
;
for
(
size_t
i
=
0
;
i
<
parametersA
.
size
();
++
i
)
{
ParameterPtr
parameterA
,
parameterB
;
parameterA
=
parametersA
[
i
];
parameterB
=
parametersB
[
i
];
CpuVector
paraA
(
parameterA
->
getSize
());
CpuVector
paraB
(
parameterB
->
getSize
());
paraA
.
copyFrom
(
*
parameterA
->
getBuf
(
PARAMETER_VALUE
));
paraB
.
copyFrom
(
*
parameterB
->
getBuf
(
PARAMETER_VALUE
));
LOG
(
INFO
)
<<
"
\n\n
----------- PARAMETER_VALUE: "
<<
parameterA
->
getName
()
<<
" ; size : "
<<
paraA
.
getSize
()
<<
" ------------"
;
checkBuffer
(
paraA
.
getData
(),
"Network A"
,
paraB
.
getData
(),
"Network B"
,
paraA
.
getSize
());
CpuVector
gradA
(
*
parameterA
->
getBuf
(
PARAMETER_GRADIENT
));
CpuVector
gradB
(
*
parameterB
->
getBuf
(
PARAMETER_GRADIENT
));
LOG
(
INFO
)
<<
"
\n\n
----------- PARAMETER_GRADIENT: "
<<
parameterA
->
getName
()
<<
" ; size : "
<<
gradA
.
getSize
()
<<
" -----------"
;
checkBuffer
(
gradA
.
getData
(),
"Network A"
,
gradB
.
getData
(),
"Network B"
,
gradA
.
getSize
());
}
}
TEST
(
Trainer
,
create
)
{
ComData
dataA
;
calcGradient
(
dataA
,
FLAGS_config_file_a
);
LOG
(
INFO
)
<<
"
\n\n
training of Network A is finished
\n\n
"
;
ComData
dataB
;
calcGradient
(
dataB
,
FLAGS_config_file_b
);
LOG
(
INFO
)
<<
"
\n\n
training of the Network B is finished
\n\n
"
;
compareGradient
(
dataA
,
dataB
);
}
int
main
(
int
argc
,
char
**
argv
)
{
paddle
::
initMain
(
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initPython
(
argc
,
argv
);
#ifndef PADDLE_TYPE_DOUBLE
if
(
FLAGS_need_high_accuracy
)
{
LOG
(
INFO
)
<<
"skip test due to it's need high accuracy"
;
return
0
;
}
if
(
FLAGS_max_diff_ratio
==
0.0
f
)
{
FLAGS_max_diff_ratio
=
2e-4
;
LOG
(
INFO
)
<<
"auto set max_diff_ratio "
<<
FLAGS_max_diff_ratio
<<
" in low accuracy mode"
;
}
#else
if
(
FLAGS_max_diff_ratio
==
0.0
f
)
{
FLAGS_max_diff_ratio
=
2e-7
;
LOG
(
INFO
)
<<
"auto set max_diff_ratio "
<<
FLAGS_max_diff_ratio
<<
" in high accuracy mode"
;
}
#endif
int
ret
=
RUN_ALL_TESTS
();
return
ret
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录