Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
99a43d86
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
12 个月 前同步成功
通知
280
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
99a43d86
编写于
1月 07, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add module creator func
上级
5f05df31
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
94 addition
and
0 deletion
+94
-0
paddle_hub/__init__.py
paddle_hub/__init__.py
+2
-0
paddle_hub/module_creator.py
paddle_hub/module_creator.py
+92
-0
未找到文件。
paddle_hub/__init__.py
浏览文件 @
99a43d86
...
...
@@ -8,3 +8,5 @@ from paddle_hub.module import Module
from
paddle_hub.module
import
ModuleConfig
from
paddle_hub.module
import
ModuleUtils
from
paddle_hub.downloader
import
download_and_uncompress
from
paddle_hub.signature
import
create_signature
from
paddle_hub.module_creator
import
create_module
paddle_hub/module_creator.py
0 → 100644
浏览文件 @
99a43d86
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle_hub.module_desc_pb2
as
modulepb
import
paddle.fluid
as
fluid
from
paddle_hub.utils
import
to_list
from
paddle_hub.signature
import
Signature
import
os
def
create_module
(
sign_arr
,
program
,
path
=
None
,
assets
=
None
):
assert
isinstance
(
program
,
fluid
.
Program
),
"program should be instance of fluid.Program"
assert
sign_arr
,
"signarture array should not be None"
if
not
path
:
path
=
"."
path
=
os
.
path
.
join
(
path
,
"hub_module"
)
assert
not
os
.
path
.
exists
(
path
),
"path %s should not be existed"
%
path
module
=
modulepb
.
ModuleDesc
()
program
=
program
.
clone
()
os
.
makedirs
(
path
)
# TODO(wuzewu): save assets data
if
not
assets
:
module
.
contain_assets
=
False
else
:
module
.
contain_assets
=
True
os
.
makedirs
(
os
.
path
.
join
(
path
,
"assets"
))
# save fluid Parameter
for
param
in
program
.
global_block
().
iter_parameters
():
parameter
=
module
.
parameters
.
add
()
parameter
.
name
=
param
.
name
parameter
.
learning_rate
=
param
.
optimize_attr
[
"learning_rate"
]
parameter
.
trainable
=
param
.
trainable
# save signarture info
sign_map
=
module
.
sign2var
sign_arr
=
to_list
(
sign_arr
)
for
sign
in
sign_arr
:
assert
isinstance
(
sign
,
Signature
),
"sign_arr should be list of Signature"
if
sign
.
get_name
()
in
sign_map
:
raise
"Error! sign_arr contains repeat signatrue %s"
%
sign
var
=
sign_map
[
sign
.
get_name
()]
feed_desc
=
var
.
feed_desc
fetch_desc
=
var
.
fetch_desc
for
input
in
sign
.
get_inputs
():
feed_var
=
feed_desc
.
add
()
feed_var
.
var_name
=
input
.
name
for
output
in
sign
.
get_outputs
():
fetch_var
=
fetch_desc
.
add
()
fetch_var
.
var_name
=
output
.
name
# save inference program
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
model_path
=
os
.
path
.
join
(
path
,
"model"
)
os
.
makedirs
(
model_path
)
first_sign
=
sign_arr
[
0
]
fluid
.
io
.
save_inference_model
(
model_path
,
feeded_var_names
=
[
var
.
name
for
var
in
first_sign
.
get_inputs
()],
target_vars
=
first_sign
.
get_outputs
(),
executor
=
exe
)
# save to dist
data
=
module
.
SerializeToString
()
metafile
=
os
.
path
.
join
(
path
,
"meta.pb"
)
with
open
(
metafile
,
"wb"
)
as
f
:
f
.
write
(
data
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录