Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
34b63ebf
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
284
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看板
提交
34b63ebf
编写于
2月 25, 2020
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the meta information of ModuleV2
上级
e88e23ca
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
89 addition
and
48 deletion
+89
-48
paddlehub/module/module.py
paddlehub/module/module.py
+89
-48
未找到文件。
paddlehub/module/module.py
浏览文件 @
34b63ebf
...
...
@@ -134,6 +134,21 @@ def runnable(func):
return
_wrapper
def
moduleinfo
(
name
,
version
,
author
,
author_email
,
summary
,
type
):
def
_wrapper
(
cls
):
if
not
issubclass
(
cls
,
Module
):
raise
RuntimeError
cls
.
_name
=
name
cls
.
_version
=
version
cls
.
_author
=
author
cls
.
_author_email
=
author_email
cls
.
_summary
=
summary
cls
.
_type
=
type
return
cls
return
_wrapper
class
Module
(
object
):
def
__new__
(
cls
,
name
=
None
,
...
...
@@ -162,7 +177,7 @@ class Module(object):
else
:
if
not
name
and
not
directory
:
directory
=
os
.
path
.
dirname
(
sys
.
modules
[
cls
.
__module__
].
__file__
)
os
.
path
.
abspath
(
sys
.
modules
[
cls
.
__module__
].
__file__
)
)
module
=
Module
.
init_with_directory
(
directory
=
directory
,
**
kwargs
)
else
:
...
...
@@ -188,25 +203,6 @@ class Module(object):
self
.
_run_func
=
None
self
.
_code_version
=
"v2"
self
.
_directory
=
directory
self
.
module_desc_path
=
os
.
path
.
join
(
self
.
directory
,
MODULE_DESC_PBNAME
)
self
.
_desc
=
module_desc_pb2
.
ModuleDesc
()
with
open
(
self
.
module_desc_path
,
"rb"
)
as
file
:
self
.
_desc
.
ParseFromString
(
file
.
read
())
module_info
=
self
.
desc
.
attr
.
map
.
data
[
'module_info'
]
self
.
_name
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'name'
])
self
.
_author
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'author'
])
self
.
_author_email
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'author_email'
])
self
.
_version
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'version'
])
self
.
_type
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'type'
])
self
.
_summary
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'summary'
])
self
.
_initialize
(
**
kwargs
)
self
.
_is_initialize
=
True
...
...
@@ -232,60 +228,57 @@ class Module(object):
@
classmethod
def
init_with_directory
(
cls
,
directory
,
**
kwargs
):
desc_file
=
os
.
path
.
join
(
directory
,
MODULE_DESC_PBNAME
)
checker
=
ModuleChecker
(
directory
)
checker
.
check
()
module_code_version
=
checker
.
module_code_version
if
module_code_version
==
"v2"
:
sys
.
path
.
insert
(
0
,
directory
)
# clear module cache
if
'module'
in
sys
.
modules
:
sys
.
modules
.
pop
(
'module'
)
_module
=
importlib
.
import_module
(
"module"
)
for
_item
,
_cls
in
inspect
.
getmembers
(
_module
,
inspect
.
isclass
):
_item
=
_module
.
__dict__
[
_item
]
if
issubclass
(
_item
,
Module
):
user_module
=
_item
(
directory
=
directory
,
**
kwargs
)
break
sys
.
path
.
pop
(
0
)
return
user_module
return
ModuleV1
(
directory
=
directory
,
**
kwargs
)
if
os
.
path
.
exists
(
desc_file
):
checker
=
ModuleChecker
(
directory
)
checker
.
check
()
return
ModuleV1
(
directory
=
directory
,
**
kwargs
)
basename
=
os
.
path
.
split
(
directory
)[
-
1
]
dirname
=
os
.
path
.
join
(
*
list
(
os
.
path
.
split
(
directory
)[:
-
1
]))
sys
.
path
.
insert
(
0
,
dirname
)
# clear module cache
if
'module'
in
sys
.
modules
:
sys
.
modules
.
pop
(
'module'
)
_module
=
importlib
.
import_module
(
"{}.module"
.
format
(
basename
))
for
_item
,
_cls
in
inspect
.
getmembers
(
_module
,
inspect
.
isclass
):
_item
=
_module
.
__dict__
[
_item
]
if
issubclass
(
_item
,
Module
):
user_module
=
_item
(
directory
=
directory
,
**
kwargs
)
break
sys
.
path
.
pop
(
0
)
return
user_module
@
property
def
run_func
(
self
):
return
self
.
_run_func
@
property
def
desc
(
self
):
return
self
.
_desc
@
property
def
directory
(
self
):
return
self
.
_directory
@
property
def
author
(
self
):
return
self
.
_author
return
self
.
_
_class__
.
_
author
@
property
def
author_email
(
self
):
return
self
.
_author_email
return
self
.
_
_class__
.
_
author_email
@
property
def
summary
(
self
):
return
self
.
_summary
return
self
.
_
_class__
.
_
summary
@
property
def
type
(
self
):
return
self
.
_type
return
self
.
_
_class__
.
_
type
@
property
def
version
(
self
):
return
self
.
_version
return
self
.
_
_class__
.
_
version
@
property
def
name
(
self
):
return
self
.
_name
return
self
.
_
_class__
.
_
name
@
property
def
code_version
(
self
):
...
...
@@ -334,6 +327,26 @@ class ModuleV1(Module):
self
.
processor
=
None
self
.
extra_info
=
{}
# parse desc
self
.
module_desc_path
=
os
.
path
.
join
(
self
.
directory
,
MODULE_DESC_PBNAME
)
self
.
_desc
=
module_desc_pb2
.
ModuleDesc
()
with
open
(
self
.
module_desc_path
,
"rb"
)
as
file
:
self
.
_desc
.
ParseFromString
(
file
.
read
())
module_info
=
self
.
desc
.
attr
.
map
.
data
[
'module_info'
]
self
.
_name
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'name'
])
self
.
_author
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'author'
])
self
.
_author_email
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'author_email'
])
self
.
_version
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'version'
])
self
.
_type
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'type'
])
self
.
_summary
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'summary'
])
# cache data
self
.
last_call_name
=
None
self
.
cache_feed_dict
=
None
...
...
@@ -356,6 +369,34 @@ class ModuleV1(Module):
self
.
_restore_parameter
(
self
.
program
)
self
.
_recover_variable_info
(
self
.
program
)
@
property
def
desc
(
self
):
return
self
.
_desc
@
property
def
author
(
self
):
return
self
.
_author
@
property
def
author_email
(
self
):
return
self
.
_author_email
@
property
def
summary
(
self
):
return
self
.
_summary
@
property
def
type
(
self
):
return
self
.
_type
@
property
def
version
(
self
):
return
self
.
_version
@
property
def
name
(
self
):
return
self
.
_name
def
_dump_processor
(
self
):
import
inspect
pymodule
=
inspect
.
getmodule
(
self
.
processor
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录