Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
569f7e83
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看板
提交
569f7e83
编写于
7月 15, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIX: cppint code style
上级
620575b6
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
88 addition
and
52 deletion
+88
-52
paddle/function/GemmConvOp.cpp
paddle/function/GemmConvOp.cpp
+3
-6
paddle/function/NaiveConvOp.cpp
paddle/function/NaiveConvOp.cpp
+1
-2
paddle/gserver/gradientmachines/NeuralNetwork.cpp
paddle/gserver/gradientmachines/NeuralNetwork.cpp
+1
-1
paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp
paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp
+1
-1
paddle/gserver/layers/AgentLayer.cpp
paddle/gserver/layers/AgentLayer.cpp
+1
-1
paddle/operators/add_op.cc
paddle/operators/add_op.cc
+16
-2
paddle/optimizer/parameter_optimizer_test.cpp
paddle/optimizer/parameter_optimizer_test.cpp
+38
-22
paddle/optimizer/serialization_test.cpp
paddle/optimizer/serialization_test.cpp
+20
-7
paddle/utils/DynamicLoader.h
paddle/utils/DynamicLoader.h
+1
-4
paddle/utils/ThreadLocal.h
paddle/utils/ThreadLocal.h
+6
-6
未找到文件。
paddle/function/GemmConvOp.cpp
浏览文件 @
569f7e83
...
...
@@ -117,8 +117,7 @@ public:
ConvFunctionBase
::
init
(
config
);
}
virtual
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
const
TensorShape
&
input
=
inputs
[
0
].
shape
();
const
TensorShape
&
filter
=
inputs
[
1
].
shape
();
const
TensorShape
&
output
=
outputs
[
0
].
shape
();
...
...
@@ -217,8 +216,7 @@ public:
ConvFunctionBase
::
init
(
config
);
}
virtual
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
const
TensorShape
&
output
=
inputs
[
0
].
shape
();
const
TensorShape
&
filter
=
inputs
[
1
].
shape
();
const
TensorShape
&
input
=
outputs
[
0
].
shape
();
...
...
@@ -311,8 +309,7 @@ public:
ConvFunctionBase
::
init
(
config
);
}
virtual
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
const
TensorShape
&
output
=
inputs
[
0
].
shape
();
const
TensorShape
&
input
=
inputs
[
1
].
shape
();
const
TensorShape
&
filter
=
outputs
[
0
].
shape
();
...
...
paddle/function/NaiveConvOp.cpp
浏览文件 @
569f7e83
...
...
@@ -90,8 +90,7 @@ public:
ConvFunctionBase
::
init
(
config
);
}
virtual
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
const
TensorShape
&
input
=
inputs
[
0
].
shape
();
const
TensorShape
&
filter
=
inputs
[
1
].
shape
();
const
TensorShape
&
output
=
outputs
[
0
].
shape
();
...
...
paddle/gserver/gradientmachines/NeuralNetwork.cpp
浏览文件 @
569f7e83
...
...
@@ -403,7 +403,7 @@ public:
:
layerName_
(
layerName
)
{
addEvaluator
(
std
::
move
(
evaluator
));
}
v
irtual
v
oid
eval
(
const
NeuralNetwork
&
nn
)
override
{
void
eval
(
const
NeuralNetwork
&
nn
)
override
{
const
LayerPtr
&
layer
=
nn
.
getLayer
(
layerName_
);
CHECK
(
layer
)
<<
"Nonexisted layer: "
<<
layerName_
<<
" in submodel "
<<
nn
.
getName
();
...
...
paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp
浏览文件 @
569f7e83
...
...
@@ -636,7 +636,7 @@ void lenToStarts(std::vector<int>& starts) {
}
starts
.
back
()
=
pos
;
}
}
}
// namespace
void
RecurrentGradientMachine
::
calcSequenceStartPositions
()
{
std
::
vector
<
int
>
starts
(
commonSeqInfo_
.
size
()
+
1
);
...
...
paddle/gserver/layers/AgentLayer.cpp
浏览文件 @
569f7e83
...
...
@@ -124,7 +124,7 @@ void copyElements(const IVector& srcVec,
dest
[
index
[
i
]]
=
src
[
i
];
}
}
}
}
// namespace
void
GatherAgentLayer
::
forwardIds
(
PassType
passType
)
{
IVectorPtr
realId
=
realLayers_
[
0
]
->
getOutputLabel
();
...
...
paddle/operators/add_op.cc
浏览文件 @
569f7e83
/* 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 <paddle/framework/op_registry.h>
#include <paddle/framework/tensor.h>
#include <paddle/operators/add_op.h>
...
...
@@ -36,9 +50,9 @@ The equation is: Out = X + Y
)DOC"
);
}
};
}
// namespace op
}
// namespace op
erators
}
// namespace paddle
REGISTER_OP
(
add_two
,
paddle
::
operators
::
AddOp
,
paddle
::
operators
::
AddOpMaker
);
REGISTER_OP_CPU_KERNEL
(
add_two
,
::
paddle
::
operators
::
AddKernel
<::
paddle
::
platform
::
CPUPlace
>
);
\ No newline at end of file
add_two
,
::
paddle
::
operators
::
AddKernel
<::
paddle
::
platform
::
CPUPlace
>
);
paddle/optimizer/parameter_optimizer_test.cpp
浏览文件 @
569f7e83
/*
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 "parameter_optimizer.h"
#include <cmath>
#include <map>
...
...
@@ -5,21 +21,18 @@
#include "gtest/gtest.h"
#include "lr_policy.h"
using
namespace
paddle
;
using
namespace
paddle
::
optimizer
;
Tensor
*
FillTensor
(
size_t
size
)
{
Tensor
*
param
=
new
Tensor
(
size
);
Tensor
&
p
=
*
param
;
paddle
::
optimizer
::
Tensor
*
FillTensor
(
size_t
size
)
{
paddle
::
optimizer
::
Tensor
*
param
=
new
paddle
::
optimizer
::
Tensor
(
size
);
paddle
::
optimizer
::
Tensor
&
p
=
*
param
;
for
(
size_t
i
=
0
;
i
<
p
.
size
();
++
i
)
{
p
[
i
]
=
(
float
)
rand
()
/
(
float
)
RAND_MAX
;
}
return
param
;
}
Tensor
*
FixedTensor
(
size_t
size
)
{
Tensor
*
param
=
new
Tensor
(
size
);
Tensor
&
p
=
*
param
;
paddle
::
optimizer
::
Tensor
*
FixedTensor
(
size_t
size
)
{
paddle
::
optimizer
::
Tensor
*
param
=
new
paddle
::
optimizer
::
Tensor
(
size
);
paddle
::
optimizer
::
Tensor
&
p
=
*
param
;
for
(
size_t
i
=
0
;
i
<
p
.
size
();
++
i
)
{
p
[
i
]
=
i
;
}
...
...
@@ -28,7 +41,8 @@ Tensor* FixedTensor(size_t size) {
class
OptimizerTest
:
public
testing
::
Test
{
public:
// init tensor shape
virtual
~
OptimizerTest
();
// init paddle::optimizer::Tensor shape
const
size_t
kSize
=
5
;
virtual
void
SetUp
()
{
...
...
@@ -38,34 +52,36 @@ public:
virtual
void
TearDown
()
{}
void
CreateSGD
()
{
Tensor
*
parameter
=
FixedTensor
(
kSize
);
config_
.
set_optimizer
(
OptimizerConfig
::
SGD
);
paddle
::
optimizer
::
Tensor
*
parameter
=
FixedTensor
(
kSize
);
config_
.
set_optimizer
(
paddle
::
OptimizerConfig
::
SGD
);
config_
.
mutable_sgd
()
->
set_momentum
(
0.0
);
config_
.
mutable_sgd
()
->
set_decay
(
0.0
);
config_
.
mutable_sgd
()
->
set_nesterov
(
false
);
config_
.
set_lr_policy
(
OptimizerConfig
::
Const
);
config_
.
set_lr_policy
(
paddle
::
OptimizerConfig
::
Const
);
config_
.
mutable_const_lr
()
->
set_learning_rate
(
0.1
);
std
::
string
str
=
config_
.
SerializeAsString
();
ParameterOptimizer
*
opt
=
ParameterOptimizer
::
Create
(
str
,
parameter
);
paddle
::
optimizer
::
ParameterOptimizer
*
opt
=
paddle
::
optimizer
::
ParameterOptimizer
::
Create
(
str
,
parameter
);
opts_
.
push_back
(
opt
);
}
void
CreateAdam
()
{
Tensor
*
parameter
=
FixedTensor
(
kSize
);
config_
.
set_optimizer
(
OptimizerConfig
::
Adam
);
paddle
::
optimizer
::
Tensor
*
parameter
=
FixedTensor
(
kSize
);
config_
.
set_optimizer
(
paddle
::
OptimizerConfig
::
Adam
);
config_
.
mutable_adam
()
->
set_beta_1
(
0.9
);
config_
.
mutable_adam
()
->
set_beta_2
(
0.1
);
config_
.
mutable_adam
()
->
set_epsilon
(
1e-3
);
config_
.
mutable_adam
()
->
set_decay
(
0.0
);
config_
.
set_lr_policy
(
OptimizerConfig
::
Const
);
config_
.
set_lr_policy
(
paddle
::
OptimizerConfig
::
Const
);
config_
.
mutable_const_lr
()
->
set_learning_rate
(
0.1
);
std
::
string
str
=
config_
.
SerializeAsString
();
ParameterOptimizer
*
opt
=
ParameterOptimizer
::
Create
(
str
,
parameter
);
paddle
::
optimizer
::
ParameterOptimizer
*
opt
=
paddle
::
optimizer
::
ParameterOptimizer
::
Create
(
str
,
parameter
);
opts_
.
push_back
(
opt
);
}
void
TestGetWeight
()
{
Tensor
*
p
=
FixedTensor
(
kSize
);
paddle
::
optimizer
::
Tensor
*
p
=
FixedTensor
(
kSize
);
for
(
size_t
i
=
0
;
i
<
opts_
.
size
();
++
i
)
{
int
s
=
0
;
float
*
newp
=
(
float
*
)
opts_
[
i
]
->
get_weight
(
&
s
);
...
...
@@ -76,7 +92,7 @@ public:
}
void
TestUpdate
()
{
Tensor
*
g
=
FixedTensor
(
kSize
);
paddle
::
optimizer
::
Tensor
*
g
=
FixedTensor
(
kSize
);
for
(
size_t
i
=
0
;
i
<
opts_
.
size
();
++
i
)
{
opts_
[
i
]
->
Update
(
g
);
}
...
...
@@ -91,8 +107,8 @@ public:
}
private:
std
::
vector
<
ParameterOptimizer
*>
opts_
;
OptimizerConfig
config_
;
std
::
vector
<
paddle
::
optimizer
::
ParameterOptimizer
*>
opts_
;
paddle
::
OptimizerConfig
config_
;
};
TEST_F
(
OptimizerTest
,
TestGetWeight
)
{
TestGetWeight
();
}
...
...
paddle/optimizer/serialization_test.cpp
浏览文件 @
569f7e83
/*
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 "serialization.h"
#include "gtest/gtest.h"
using
namespace
paddle
;
using
namespace
paddle
::
optimizer
;
TEST
(
TensorToProto
,
Case1
)
{
Tensor
t
(
3
),
t1
(
3
);
paddle
::
optimizer
::
Tensor
t
(
3
),
t1
(
3
);
for
(
size_t
i
=
0
;
i
<
t
.
size
();
++
i
)
{
t
[
i
]
=
i
;
t1
[
i
]
=
0
;
}
TensorProto
proto
;
TensorToProto
(
t
,
&
proto
);
ProtoToTensor
(
proto
,
&
t1
);
paddle
::
TensorProto
proto
;
paddle
::
optimizer
::
TensorToProto
(
t
,
&
proto
);
paddle
::
optimizer
::
ProtoToTensor
(
proto
,
&
t1
);
for
(
size_t
i
=
0
;
i
<
t1
.
size
();
++
i
)
{
EXPECT_EQ
(
t1
[
i
],
t
[
i
]);
}
...
...
paddle/utils/DynamicLoader.h
浏览文件 @
569f7e83
...
...
@@ -12,8 +12,7 @@ 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. */
#ifndef DYNAMIC_LOAD_H_
#define DYNAMIC_LOAD_H_
#pragma once
#include <dlfcn.h>
#include <memory>
...
...
@@ -59,5 +58,3 @@ void GetWarpCTCDsoHandle(void** dso_handle);
*
*/
void
GetLapackDsoHandle
(
void
**
dso_handle
);
#endif // DYNAMIC_LOAD_H_
paddle/utils/ThreadLocal.h
浏览文件 @
569f7e83
...
...
@@ -51,7 +51,7 @@ template <class T>
class
ThreadLocal
{
public:
ThreadLocal
()
{
CHECK
(
pthread_key_create
(
&
threadSpecificKey_
,
dataDestructor
)
==
0
);
CHECK
_EQ
(
pthread_key_create
(
&
threadSpecificKey_
,
dataDestructor
),
0
);
}
~
ThreadLocal
()
{
pthread_key_delete
(
threadSpecificKey_
);
}
...
...
@@ -65,7 +65,7 @@ public:
if
(
!
p
&&
createLocal
)
{
p
=
new
T
();
int
ret
=
pthread_setspecific
(
threadSpecificKey_
,
p
);
CHECK
(
ret
==
0
);
CHECK
_EQ
(
ret
,
0
);
}
return
p
;
}
...
...
@@ -79,7 +79,7 @@ public:
if
(
T
*
q
=
get
(
false
))
{
dataDestructor
(
q
);
}
CHECK
(
pthread_setspecific
(
threadSpecificKey_
,
p
)
==
0
);
CHECK
_EQ
(
pthread_setspecific
(
threadSpecificKey_
,
p
),
0
);
}
/**
...
...
@@ -112,7 +112,7 @@ private:
template
<
class
T
>
class
ThreadLocalD
{
public:
ThreadLocalD
()
{
CHECK
(
pthread_key_create
(
&
threadSpecificKey_
,
NULL
)
==
0
);
}
ThreadLocalD
()
{
CHECK
_EQ
(
pthread_key_create
(
&
threadSpecificKey_
,
NULL
),
0
);
}
~
ThreadLocalD
()
{
pthread_key_delete
(
threadSpecificKey_
);
for
(
auto
t
:
threadMap_
)
{
...
...
@@ -127,7 +127,7 @@ public:
T
*
p
=
(
T
*
)
pthread_getspecific
(
threadSpecificKey_
);
if
(
!
p
)
{
p
=
new
T
();
CHECK
(
pthread_setspecific
(
threadSpecificKey_
,
p
)
==
0
);
CHECK
_EQ
(
pthread_setspecific
(
threadSpecificKey_
,
p
),
0
);
updateMap
(
p
);
}
return
p
;
...
...
@@ -141,7 +141,7 @@ public:
if
(
T
*
q
=
(
T
*
)
pthread_getspecific
(
threadSpecificKey_
))
{
dataDestructor
(
q
);
}
CHECK
(
pthread_setspecific
(
threadSpecificKey_
,
p
)
==
0
);
CHECK
_EQ
(
pthread_setspecific
(
threadSpecificKey_
,
p
),
0
);
updateMap
(
p
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录