Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
a0d1c58d
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a0d1c58d
编写于
2月 14, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix serialization bug
上级
1ebde3bd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
12 deletion
+44
-12
paddle_hub/paddle_helper.py
paddle_hub/paddle_helper.py
+14
-4
paddle_hub/utils.py
paddle_hub/utils.py
+30
-8
未找到文件。
paddle_hub/paddle_helper.py
浏览文件 @
a0d1c58d
...
...
@@ -48,6 +48,12 @@ def get_variable_info(var):
def
from_param_to_flexible_data
(
param
,
flexible_data
):
def
paddle_obj_filter
(
pyobj
):
return
isinstance
(
pyobj
,
fluid
.
framework
.
Variable
)
or
isinstance
(
pyobj
,
fluid
.
framework
.
Block
)
or
isinstance
(
pyobj
,
fluid
.
framework
.
Program
)
or
isinstance
(
pyobj
,
fluid
.
framework
.
Operator
)
flexible_data
.
type
=
module_desc_pb2
.
MAP
from_pyobj_to_flexible_data
(
param
.
trainable
,
flexible_data
.
map
.
data
[
'trainable'
])
...
...
@@ -55,10 +61,14 @@ def from_param_to_flexible_data(param, flexible_data):
flexible_data
.
map
.
data
[
'do_model_average'
])
from_pyobj_to_flexible_data
(
param
.
optimize_attr
,
flexible_data
.
map
.
data
[
'optimize_attr'
])
from_pyobj_to_flexible_data
(
param
.
regularizer
,
flexible_data
.
map
.
data
[
'regularizer'
])
from_pyobj_to_flexible_data
(
param
.
gradient_clip_attr
,
flexible_data
.
map
.
data
[
'gradient_clip_attr'
])
from_pyobj_to_flexible_data
(
param
.
regularizer
,
flexible_data
.
map
.
data
[
'regularizer'
],
obj_filter
=
paddle_obj_filter
)
from_pyobj_to_flexible_data
(
param
.
gradient_clip_attr
,
flexible_data
.
map
.
data
[
'gradient_clip_attr'
],
obj_filter
=
paddle_obj_filter
)
def
from_flexible_data_to_param
(
flexible_data
):
...
...
paddle_hub/utils.py
浏览文件 @
a0d1c58d
...
...
@@ -51,7 +51,23 @@ def get_keyed_type_of_pyobj(pyobj):
return
module_desc_pb2
.
STRING
def
from_pyobj_to_flexible_data
(
pyobj
,
flexible_data
):
def
get_pykey
(
key
,
keyed_type
):
if
keyed_type
==
module_desc_pb2
.
BOOLEAN
:
return
bool
(
key
)
elif
keyed_type
==
module_desc_pb2
.
INT
:
return
int
(
key
)
elif
keyed_type
==
module_desc_pb2
.
STRING
:
return
str
(
key
)
elif
keyed_type
==
module_desc_pb2
.
FLOAT
:
return
float
(
key
)
return
str
(
key
)
#TODO(wuzewu): solving the problem of circular references
def
from_pyobj_to_flexible_data
(
pyobj
,
flexible_data
,
obj_filter
=
None
):
if
obj_filter
and
obj_filter
(
pyobj
):
logger
.
info
(
"filter python object"
)
return
if
isinstance
(
pyobj
,
bool
):
flexible_data
.
type
=
module_desc_pb2
.
BOOLEAN
flexible_data
.
b
=
pyobj
...
...
@@ -67,25 +83,31 @@ def from_pyobj_to_flexible_data(pyobj, flexible_data):
elif
isinstance
(
pyobj
,
list
)
or
isinstance
(
pyobj
,
tuple
):
flexible_data
.
type
=
module_desc_pb2
.
LIST
for
index
,
obj
in
enumerate
(
pyobj
):
from_pyobj_to_flexible_data
(
obj
,
flexible_data
.
list
.
data
[
str
(
index
)]
)
from_pyobj_to_flexible_data
(
obj
,
flexible_data
.
list
.
data
[
str
(
index
)],
obj_filter
)
elif
isinstance
(
pyobj
,
set
):
flexible_data
.
type
=
module_desc_pb2
.
SET
for
index
,
obj
in
enumerate
(
list
(
pyobj
)):
from_pyobj_to_flexible_data
(
obj
,
flexible_data
.
set
.
data
[
str
(
index
)])
from_pyobj_to_flexible_data
(
obj
,
flexible_data
.
set
.
data
[
str
(
index
)],
obj_filter
)
elif
isinstance
(
pyobj
,
dict
):
flexible_data
.
type
=
module_desc_pb2
.
MAP
for
key
,
value
in
pyobj
.
items
():
from_pyobj_to_flexible_data
(
value
,
flexible_data
.
map
.
data
[
str
(
key
)])
from_pyobj_to_flexible_data
(
value
,
flexible_data
.
map
.
data
[
str
(
key
)],
obj_filter
)
flexible_data
.
map
.
keyType
[
str
(
key
)]
=
get_keyed_type_of_pyobj
(
key
)
elif
isinstance
(
pyobj
,
type
(
None
)):
flexible_data
.
type
=
module_desc_pb2
.
NONE
else
:
flexible_data
.
type
=
module_desc_pb2
.
OBJECT
flexible_data
.
name
=
str
(
pyobj
.
__class__
.
__name__
)
if
not
hasattr
(
pyobj
,
"__dict__"
):
logger
.
warning
(
"python obj %s has not __dict__ attr"
%
flexible_data
.
name
)
return
for
key
,
value
in
pyobj
.
__dict__
.
items
():
from_pyobj_to_flexible_data
(
value
,
flexible_data
.
object
.
data
[
str
(
key
)]
)
from_pyobj_to_flexible_data
(
value
,
flexible_data
.
object
.
data
[
str
(
key
)],
obj_filter
)
flexible_data
.
object
.
keyType
[
str
(
key
)]
=
get_keyed_type_of_pyobj
(
key
)
...
...
@@ -112,7 +134,7 @@ def from_flexible_data_to_pyobj(flexible_data):
elif
flexible_data
.
type
==
module_desc_pb2
.
MAP
:
result
=
{}
for
key
,
value
in
flexible_data
.
map
.
data
.
items
():
key
=
flexible_data
.
map
.
keyType
[
key
]
key
=
get_pykey
(
key
,
flexible_data
.
map
.
keyType
[
key
])
result
[
key
]
=
from_flexible_data_to_pyobj
(
value
)
elif
flexible_data
.
type
==
module_desc_pb2
.
NONE
:
result
=
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录