Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a765c7c3
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看板
提交
a765c7c3
编写于
7年前
作者:
Y
Yu Yang
提交者:
GitHub
7年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1013 from reyoung/feature/add_sum_cost_in_args
Add some functions to PaddleAPI.h
上级
cb0a1e2f
b23d99dd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
0 deletion
+26
-0
paddle/api/Arguments.cpp
paddle/api/Arguments.cpp
+4
-0
paddle/api/PaddleAPI.h
paddle/api/PaddleAPI.h
+6
-0
paddle/api/Parameter.cpp
paddle/api/Parameter.cpp
+8
-0
paddle/api/test/.gitignore
paddle/api/test/.gitignore
+2
-0
paddle/api/test/testArguments.py
paddle/api/test/testArguments.py
+2
-0
paddle/api/test/testGradientMachine.py
paddle/api/test/testGradientMachine.py
+4
-0
未找到文件。
paddle/api/Arguments.cpp
浏览文件 @
a765c7c3
...
@@ -137,6 +137,10 @@ void Arguments::setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError) {
...
@@ -137,6 +137,10 @@ void Arguments::setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError) {
a
.
cpuSequenceDims
=
m
->
cast
<
paddle
::
IVector
>
(
vec
->
getSharedPtr
());
a
.
cpuSequenceDims
=
m
->
cast
<
paddle
::
IVector
>
(
vec
->
getSharedPtr
());
}
}
float
Arguments
::
sumCosts
()
const
{
return
paddle
::
Argument
::
sumCosts
(
m
->
outputs
);
}
int64_t
Arguments
::
getBatchSize
(
size_t
idx
)
const
throw
(
RangeError
)
{
int64_t
Arguments
::
getBatchSize
(
size_t
idx
)
const
throw
(
RangeError
)
{
auto
&
a
=
m
->
getArg
(
idx
);
auto
&
a
=
m
->
getArg
(
idx
);
return
a
.
getBatchSize
();
return
a
.
getBatchSize
();
...
...
This diff is collapsed.
Click to expand it.
paddle/api/PaddleAPI.h
浏览文件 @
a765c7c3
...
@@ -450,6 +450,8 @@ public:
...
@@ -450,6 +450,8 @@ public:
IVector
*
vec
)
throw
(
RangeError
);
IVector
*
vec
)
throw
(
RangeError
);
void
setSlotSequenceDim
(
size_t
idx
,
IVector
*
vec
)
throw
(
RangeError
);
void
setSlotSequenceDim
(
size_t
idx
,
IVector
*
vec
)
throw
(
RangeError
);
float
sumCosts
()
const
;
private:
private:
static
Arguments
*
createByPaddleArgumentVector
(
void
*
ptr
);
static
Arguments
*
createByPaddleArgumentVector
(
void
*
ptr
);
void
*
getInternalArgumentsPtr
()
const
;
void
*
getInternalArgumentsPtr
()
const
;
...
@@ -546,6 +548,10 @@ public:
...
@@ -546,6 +548,10 @@ public:
ParameterConfig
*
getConfig
();
ParameterConfig
*
getConfig
();
void
setValueUpdated
();
void
setValueUpdated
();
bool
save
(
const
std
::
string
&
filename
)
const
;
bool
load
(
const
std
::
string
&
filename
)
const
;
size_t
getSize
()
const
;
size_t
getSize
()
const
;
private:
private:
...
...
This diff is collapsed.
Click to expand it.
paddle/api/Parameter.cpp
浏览文件 @
a765c7c3
...
@@ -57,4 +57,12 @@ size_t Parameter::getID() const { return m->getPtr()->getID(); }
...
@@ -57,4 +57,12 @@ size_t Parameter::getID() const { return m->getPtr()->getID(); }
void
Parameter
::
setValueUpdated
()
{
m
->
getPtr
()
->
setValueUpdated
();
}
void
Parameter
::
setValueUpdated
()
{
m
->
getPtr
()
->
setValueUpdated
();
}
bool
Parameter
::
save
(
const
std
::
string
&
filename
)
const
{
return
m
->
getPtr
()
->
save
(
filename
);
}
bool
Parameter
::
load
(
const
std
::
string
&
filename
)
const
{
return
m
->
getPtr
()
->
load
(
filename
);
}
size_t
Parameter
::
getSize
()
const
{
return
m
->
getPtr
()
->
getSize
();
}
size_t
Parameter
::
getSize
()
const
{
return
m
->
getPtr
()
->
getSize
();
}
This diff is collapsed.
Click to expand it.
paddle/api/test/.gitignore
0 → 100644
浏览文件 @
a765c7c3
*.w0
*.wbias
This diff is collapsed.
Click to expand it.
paddle/api/test/testArguments.py
浏览文件 @
a765c7c3
...
@@ -22,6 +22,8 @@ class TestArguments(unittest.TestCase):
...
@@ -22,6 +22,8 @@ class TestArguments(unittest.TestCase):
args
=
swig_paddle
.
Arguments
.
createArguments
(
1
)
args
=
swig_paddle
.
Arguments
.
createArguments
(
1
)
args
.
setSlotValue
(
0
,
m
)
args
.
setSlotValue
(
0
,
m
)
self
.
assertAlmostEqual
(
27.0
,
args
.
sumCosts
())
mat
=
args
.
getSlotValue
(
0
)
mat
=
args
.
getSlotValue
(
0
)
assert
isinstance
(
mat
,
swig_paddle
.
Matrix
)
assert
isinstance
(
mat
,
swig_paddle
.
Matrix
)
np_mat
=
mat
.
toNumpyMatInplace
()
np_mat
=
mat
.
toNumpyMatInplace
()
...
...
This diff is collapsed.
Click to expand it.
paddle/api/test/testGradientMachine.py
浏览文件 @
a765c7c3
...
@@ -45,6 +45,7 @@ class TestGradientMachine(unittest.TestCase):
...
@@ -45,6 +45,7 @@ class TestGradientMachine(unittest.TestCase):
assert
isinstance
(
val
,
swig_paddle
.
Vector
)
assert
isinstance
(
val
,
swig_paddle
.
Vector
)
arr
=
numpy
.
full
((
len
(
val
),
),
0.1
,
dtype
=
"float32"
)
arr
=
numpy
.
full
((
len
(
val
),
),
0.1
,
dtype
=
"float32"
)
val
.
copyFromNumpyArray
(
arr
)
val
.
copyFromNumpyArray
(
arr
)
self
.
assertTrue
(
param
.
save
(
param
.
getName
()))
param_config
=
param
.
getConfig
().
toProto
()
param_config
=
param
.
getConfig
().
toProto
()
assert
isinstance
(
param_config
,
assert
isinstance
(
param_config
,
paddle
.
proto
.
ParameterConfig_pb2
.
ParameterConfig
)
paddle
.
proto
.
ParameterConfig_pb2
.
ParameterConfig
)
...
@@ -92,6 +93,9 @@ class TestGradientMachine(unittest.TestCase):
...
@@ -92,6 +93,9 @@ class TestGradientMachine(unittest.TestCase):
self
.
assertTrue
(
self
.
isCalled
)
self
.
assertTrue
(
self
.
isCalled
)
for
param
in
machine
.
getParameters
():
self
.
assertTrue
(
param
.
load
(
param
.
getName
()))
def
test_train_one_pass
(
self
):
def
test_train_one_pass
(
self
):
conf_file_path
=
'./testTrainConfig.py'
conf_file_path
=
'./testTrainConfig.py'
trainer_config
=
swig_paddle
.
TrainerConfig
.
createFromTrainerConfigFile
(
trainer_config
=
swig_paddle
.
TrainerConfig
.
createFromTrainerConfigFile
(
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部