Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
e148bc15
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e148bc15
编写于
6月 15, 2017
作者:
D
dzhwinter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"remove unused tensor line"
上级
1814fc29
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
16 addition
and
9 deletion
+16
-9
cmake/util.cmake
cmake/util.cmake
+1
-0
paddle/optimizer/CMakeLists.txt
paddle/optimizer/CMakeLists.txt
+2
-3
paddle/optimizer/Tensor.h
paddle/optimizer/Tensor.h
+5
-1
paddle/optimizer/parameter_optimizer_test.cpp
paddle/optimizer/parameter_optimizer_test.cpp
+4
-4
paddle/optimizer/serialization.h
paddle/optimizer/serialization.h
+3
-1
paddle/optimizer/serialization_test.cpp
paddle/optimizer/serialization_test.cpp
+1
-0
未找到文件。
cmake/util.cmake
浏览文件 @
e148bc15
...
...
@@ -84,6 +84,7 @@ function(link_paddle_exe TARGET_NAME)
paddle_parameter
paddle_proto
paddle_cuda
paddle_optimizer
${
EXTERNAL_LIBS
}
${
CMAKE_THREAD_LIBS_INIT
}
${
CMAKE_DL_LIBS
}
...
...
paddle/optimizer/CMakeLists.txt
浏览文件 @
e148bc15
...
...
@@ -9,9 +9,8 @@ set(OPITMIZER_SRCS
sgd_optimizer.cc
)
add_library
(
optimizer STATIC
${
OPITMIZER_SRCS
}
)
add_dependencies
(
optimizer gen_proto_cpp
)
add_library
(
paddle_
optimizer STATIC
${
OPITMIZER_SRCS
}
)
add_dependencies
(
paddle_
optimizer gen_proto_cpp
)
add_simple_unittest
(
serialization_test
)
add_simple_unittest
(
parameter_optimizer_test
)
add_dependencies
(
parameter_optimizer_test optimizer
)
paddle/optimizer/Tensor.h
浏览文件 @
e148bc15
...
...
@@ -15,13 +15,17 @@ template <class T>
class
TensorT
{
public:
TensorT
(
size_t
size
)
:
height_
(
1
),
width_
(
size
)
{
data_
=
new
T
[
size
];
}
TensorT
(
T
*
data
,
size_t
size
)
:
height_
(
1
),
width_
(
size
),
data_
(
data
)
{}
TensorT
(
T
*
data
,
size_t
h
,
size_t
w
)
:
height_
(
h
),
width_
(
w
),
data_
(
data_
)
{}
TensorT
(
T
*
data
,
size_t
h
,
size_t
w
)
:
height_
(
h
),
width_
(
w
),
data_
(
data
)
{}
~
TensorT
()
{
if
(
data_
)
delete
data_
;
}
T
*
get_buffer
()
{
return
this
->
data_
;
}
T
&
operator
[](
const
size_t
idx
)
{
CHECK
(
idx
>=
0
&&
idx
<
this
->
width_
)
<<
"out of index range"
;
return
data_
[
idx
];
...
...
paddle/optimizer/parameter_optimizer_test.cpp
浏览文件 @
e148bc15
...
...
@@ -49,8 +49,8 @@ public:
config_
.
set_lr_policy
(
OptimizerConfig
::
ConstLr
);
config_
.
mutable_const_lr
()
->
set_learning_rate
(
0.1
);
ParameterOptimizer
*
opt
=
ParameterOptimizer
::
Create
(
config_
.
SerializeAsString
()
,
parameter
);
std
::
string
str
=
config_
.
SerializeAsString
();
ParameterOptimizer
*
opt
=
ParameterOptimizer
::
Create
(
str
,
parameter
);
opts_
.
push_back
(
opt
);
opts_table_
[
opts_
.
size
()]
=
OptimizerConfig
::
SGD
;
}
...
...
@@ -64,8 +64,8 @@ public:
config_
.
mutable_adam
()
->
set_decay
(
0.0
);
config_
.
set_lr_policy
(
OptimizerConfig
::
ConstLr
);
config_
.
mutable_const_lr
()
->
set_learning_rate
(
0.1
);
ParameterOptimizer
*
opt
=
ParameterOptimizer
::
Create
(
config_
.
SerializeAsString
()
,
parameter
);
std
::
string
str
=
config_
.
SerializeAsString
();
ParameterOptimizer
*
opt
=
ParameterOptimizer
::
Create
(
str
,
parameter
);
opts_
.
push_back
(
opt
);
opts_table_
[
opts_
.
size
()]
=
OptimizerConfig
::
Adam
;
}
...
...
paddle/optimizer/serialization.h
浏览文件 @
e148bc15
#pragma once
#include <iostream>
#include <sstream>
#include <string>
#include <type_traits>
...
...
@@ -16,7 +17,7 @@ static void TensorToProto(const Tensor& tensor, TensorProto* proto) {
for
(
size_t
i
=
0
;
i
<
tensor
.
size
();
++
i
)
{
os
<<
tensor
[
i
];
proto
->
add_content
(
os
.
str
());
os
.
clear
(
);
os
.
str
(
std
::
string
()
);
}
}
...
...
@@ -25,6 +26,7 @@ static void ProtoToTensor(const TensorProto& proto, Tensor* tensor) {
for
(
auto
i
=
0
;
i
<
proto
.
content_size
();
++
i
)
{
sin
<<
proto
.
content
(
i
);
sin
>>
(
*
tensor
)[
i
];
sin
.
str
(
std
::
string
());
sin
.
clear
();
}
}
...
...
paddle/optimizer/serialization_test.cpp
浏览文件 @
e148bc15
...
...
@@ -10,6 +10,7 @@ TEST(TensorToProto, Case1) {
t
[
i
]
=
i
;
t1
[
i
]
=
0
;
}
TensorProto
proto
;
TensorToProto
(
t
,
&
proto
);
ProtoToTensor
(
proto
,
&
t1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录