Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
a77d2866
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
281
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,发现更多精彩内容 >>
提交
a77d2866
编写于
1月 08, 2019
作者:
Z
Zeyu Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move remove feed and fetch op into Module.__init__()
上级
1282b844
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
4 deletion
+13
-4
example/sentiment-classification/sentiment_classify.py
example/sentiment-classification/sentiment_classify.py
+9
-2
example/sentiment-classification/test_finetune.py
example/sentiment-classification/test_finetune.py
+1
-2
paddle_hub/module.py
paddle_hub/module.py
+3
-0
未找到文件。
example/sentiment-classification/sentiment_classify.py
浏览文件 @
a77d2866
...
...
@@ -124,6 +124,11 @@ def train_net(train_reader,
sgd_optimizer
=
fluid
.
optimizer
.
Adagrad
(
learning_rate
=
lr
)
sgd_optimizer
.
minimize
(
cost
)
# write default main program
with
open
(
"./bow_net.backward.program_desc.prototxt"
,
"w"
)
as
fo
:
program_desc
=
str
(
fluid
.
default_main_program
())
fo
.
write
(
program_desc
)
# set place, executor, datafeeder
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
...
...
@@ -191,7 +196,6 @@ def retrain_net(train_reader,
dict_dim
=
len
(
word_dict
)
+
2
module_dir
=
os
.
path
.
join
(
save_dirname
,
network_name
)
print
(
"module_dir"
,
module_dir
)
module
=
hub
.
Module
(
module_dir
=
module_dir
)
main_program
=
fluid
.
Program
()
...
...
@@ -201,7 +205,7 @@ def retrain_net(train_reader,
fluid
.
framework
.
switch_main_program
(
module
.
get_inference_program
())
# remove feed fetch operator and variable
hub
.
ModuleUtils
.
remove_feed_fetch_op
(
fluid
.
default_main_program
())
#
hub.ModuleUtils.remove_feed_fetch_op(fluid.default_main_program())
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
data
=
module
.
get_feed_var_by_index
(
0
)
...
...
@@ -221,6 +225,9 @@ def retrain_net(train_reader,
sgd_optimizer
=
fluid
.
optimizer
.
Adagrad
(
learning_rate
=
lr
)
sgd_optimizer
.
minimize
(
cost
)
with
open
(
"./prototxt/bow_net.finetune.program_desc.prototxt"
,
"w"
)
as
fo
:
program_desc
=
str
(
fluid
.
default_main_program
())
fo
.
write
(
program_desc
)
# set place, executor, datafeeder
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
...
...
example/sentiment-classification/test_finetune.py
浏览文件 @
a77d2866
...
...
@@ -145,8 +145,7 @@ def retrain_net(train_reader,
fluid
.
framework
.
switch_main_program
(
module
.
get_inference_program
())
# remove feed fetch operator and variable
hub
.
ModuleUtils
.
remove_feed_fetch_op
(
fluid
.
default_main_program
())
# remove_feed_fetch_op(fluid.default_main_program())
# hub.ModuleUtils.remove_feed_fetch_op(fluid.default_main_program())
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
#data = fluid.default_main_program().global_block().var("words")
...
...
paddle_hub/module.py
浏览文件 @
a77d2866
...
...
@@ -72,6 +72,9 @@ class Module(object):
self
.
fetch_targets
]
=
fluid
.
io
.
load_inference_model
(
dirname
=
model_dir
,
executor
=
self
.
exe
)
# remove feed fetch operator and variable
ModuleUtils
.
remove_feed_fetch_op
(
self
.
inference_program
)
print
(
"inference_program"
)
print
(
self
.
inference_program
)
print
(
"feed_target_names"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录