Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
f6e1d959
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
12 个月 前同步成功
通知
692
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f6e1d959
编写于
10月 18, 2017
作者:
Y
Yu Yang
提交者:
GitHub
10月 18, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Expose VarDesc::persistable to Python (#4911)
上级
7ad13fbf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
11 deletion
+36
-11
paddle/framework/var_desc.h
paddle/framework/var_desc.h
+4
-0
paddle/pybind/protobuf.cc
paddle/pybind/protobuf.cc
+13
-10
python/paddle/v2/framework/framework.py
python/paddle/v2/framework/framework.py
+19
-1
未找到文件。
paddle/framework/var_desc.h
浏览文件 @
f6e1d959
...
...
@@ -79,6 +79,10 @@ class VarDescBind {
void
SetType
(
VarDesc
::
VarType
type
)
{
desc_
.
set_type
(
type
);
}
bool
Persistable
()
const
{
return
desc_
.
persistable
();
}
void
SetPersistable
(
bool
persistable
)
{
desc_
.
set_persistable
(
persistable
);
}
private:
const
TensorDesc
&
tensor_desc
()
const
;
TensorDesc
*
mutable_tensor_desc
();
...
...
paddle/pybind/protobuf.cc
浏览文件 @
f6e1d959
...
...
@@ -202,16 +202,19 @@ void BindVarDsec(py::module &m) {
.
def
(
"set_lod_level"
,
&
VarDescBind
::
SetLoDLevel
)
.
def
(
"type"
,
&
VarDescBind
::
GetType
)
.
def
(
"set_type"
,
&
VarDescBind
::
SetType
)
.
def
(
"serialize_to_string"
,
[](
VarDescBind
&
var_desc
)
->
py
::
bytes
{
const
VarDesc
*
desc
=
var_desc
.
Proto
();
PADDLE_ENFORCE
(
desc
->
IsInitialized
(),
"VarDesc has not been initialized."
);
std
::
string
res
;
PADDLE_ENFORCE
(
desc
->
SerializeToString
(
&
res
),
"Serialize VarDesc Error. This could be a bug of Paddle."
);
return
res
;
});
.
def
(
"serialize_to_string"
,
[](
VarDescBind
&
var_desc
)
->
py
::
bytes
{
const
VarDesc
*
desc
=
var_desc
.
Proto
();
PADDLE_ENFORCE
(
desc
->
IsInitialized
(),
"VarDesc has not been initialized."
);
std
::
string
res
;
PADDLE_ENFORCE
(
desc
->
SerializeToString
(
&
res
),
"Serialize VarDesc Error. This could be a bug of Paddle."
);
return
res
;
})
.
def
(
"persistable"
,
&
VarDescBind
::
Persistable
)
.
def
(
"set_persistable"
,
&
VarDescBind
::
SetPersistable
);
py
::
enum_
<
VarDesc
::
VarType
>
(
var_desc
,
"VarType"
,
""
)
.
value
(
"LOD_TENSOR"
,
VarDesc
::
LOD_TENSOR
)
...
...
python/paddle/v2/framework/framework.py
浏览文件 @
f6e1d959
...
...
@@ -15,6 +15,7 @@ class Variable(object):
shape
=
None
,
dtype
=
None
,
lod_level
=
None
,
persistable
=
False
,
**
kwargs
):
self
.
block
=
block
...
...
@@ -70,6 +71,17 @@ class Variable(object):
"lod_level is {2}. They are not "
"matched"
.
format
(
self
.
name
,
self
.
lod_level
,
lod_level
))
if
persistable
is
not
None
:
if
is_new_var
:
self
.
desc
.
set_persistable
(
persistable
)
else
:
if
persistable
!=
self
.
persistable
:
raise
ValueError
(
"Variable {0} has been created before."
"The previous persistable is {1}; the new "
"persistable is {2}. They are not matched"
.
format
(
self
.
name
,
self
.
persistable
,
persistable
))
self
.
block
.
vars
[
name
]
=
self
self
.
op
=
None
...
...
@@ -80,6 +92,10 @@ class Variable(object):
__repr__
=
__str__
@
property
def
persistable
(
self
):
return
self
.
desc
.
persistable
()
@
property
def
name
(
self
):
return
self
.
desc
.
name
()
...
...
@@ -445,7 +461,9 @@ class Parameter(Variable):
if
each
<
0
:
raise
ValueError
(
"Parameter shape should not be related with "
"batch-size"
)
Variable
.
__init__
(
self
,
block
,
shape
=
shape
,
dtype
=
dtype
,
**
kwargs
)
Variable
.
__init__
(
self
,
block
,
persistable
=
True
,
shape
=
shape
,
dtype
=
dtype
,
**
kwargs
)
self
.
trainable
=
kwargs
.
get
(
'trainable'
,
True
)
self
.
init_attr
=
kwargs
.
get
(
'initialize_attr'
,
{
'type'
:
'uniform_random'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录