Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
5a44a789
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看板
提交
5a44a789
编写于
6月 17, 2019
作者:
S
Steffy-zxf
提交者:
wuzewu
6月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update tasks whose output type is list (#55)
上级
a271703a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
20 addition
and
16 deletion
+20
-16
paddlehub/finetune/task.py
paddlehub/finetune/task.py
+20
-16
未找到文件。
paddlehub/finetune/task.py
浏览文件 @
5a44a789
...
...
@@ -163,7 +163,7 @@ class BasicTask(object):
with
fluid
.
program_guard
(
self
.
env
.
main_program
,
self
.
_base_startup_program
):
with
fluid
.
unique_name
.
guard
(
self
.
env
.
UNG
):
self
.
env
.
output
=
self
.
_build_net
()
self
.
env
.
output
s
=
self
.
_build_net
()
if
self
.
is_train_phase
or
self
.
is_test_phase
:
self
.
env
.
label
=
self
.
_add_label
()
self
.
env
.
loss
=
self
.
_add_loss
()
...
...
@@ -200,8 +200,11 @@ class BasicTask(object):
self
.
env
.
main_program
=
t_program
self
.
env
.
loss
=
self
.
env
.
main_program
.
global_block
().
vars
[
self
.
env
.
loss
.
name
]
self
.
env
.
output
=
self
.
env
.
main_program
.
global_block
().
vars
[
self
.
env
.
output
.
name
]
outputs_name
=
[
var
.
name
for
var
in
self
.
env
.
outputs
]
self
.
env
.
outputs
=
[
self
.
env
.
main_program
.
global_block
().
vars
[
name
]
for
name
in
outputs_name
]
metrics_name
=
[
var
.
name
for
var
in
self
.
env
.
metrics
]
self
.
env
.
metrics
=
[
self
.
env
.
main_program
.
global_block
().
vars
[
name
]
...
...
@@ -344,10 +347,10 @@ class BasicTask(object):
return
self
.
env
.
label
@
property
def
output
(
self
):
def
output
s
(
self
):
if
not
self
.
env
.
is_inititalized
:
self
.
_build_env
()
return
self
.
env
.
output
return
self
.
env
.
output
s
@
property
def
metrics
(
self
):
...
...
@@ -378,7 +381,7 @@ class BasicTask(object):
def
fetch_list
(
self
):
if
self
.
is_train_phase
or
self
.
is_test_phase
:
return
[
metric
.
name
for
metric
in
self
.
metrics
]
+
[
self
.
loss
.
name
]
return
[
self
.
output
.
name
]
return
[
output
.
name
for
output
in
self
.
outputs
]
def
_build_env_start_event
(
self
):
pass
...
...
@@ -611,18 +614,18 @@ class ClassifierTask(BasicTask):
name
=
"cls_out_b"
,
initializer
=
fluid
.
initializer
.
Constant
(
0.
)),
act
=
"softmax"
)
return
logits
return
[
logits
]
def
_add_label
(
self
):
return
fluid
.
layers
.
data
(
name
=
"label"
,
dtype
=
"int64"
,
shape
=
[
1
])
def
_add_loss
(
self
):
ce_loss
=
fluid
.
layers
.
cross_entropy
(
input
=
self
.
output
,
label
=
self
.
label
)
input
=
self
.
output
s
[
0
]
,
label
=
self
.
label
)
return
fluid
.
layers
.
mean
(
x
=
ce_loss
)
def
_add_metrics
(
self
):
return
[
fluid
.
layers
.
accuracy
(
input
=
self
.
output
,
label
=
self
.
label
)]
return
[
fluid
.
layers
.
accuracy
(
input
=
self
.
output
s
[
0
]
,
label
=
self
.
label
)]
def
_build_env_end_event
(
self
):
with
self
.
log_writer
.
mode
(
self
.
phase
)
as
logw
:
...
...
@@ -720,7 +723,7 @@ class TextClassifierTask(ClassifierTask):
name
=
"cls_out_b"
,
initializer
=
fluid
.
initializer
.
Constant
(
0.
)),
act
=
"softmax"
)
return
logits
return
[
logits
]
class
SequenceLabelTask
(
BasicTask
):
...
...
@@ -773,7 +776,7 @@ class SequenceLabelTask(BasicTask):
logits
=
fluid
.
layers
.
flatten
(
logits
,
axis
=
2
)
logits
=
fluid
.
layers
.
softmax
(
logits
)
self
.
num_labels
=
logits
.
shape
[
1
]
return
logits
return
[
logits
]
def
_add_label
(
self
):
label
=
fluid
.
layers
.
data
(
...
...
@@ -782,7 +785,8 @@ class SequenceLabelTask(BasicTask):
def
_add_loss
(
self
):
labels
=
fluid
.
layers
.
flatten
(
self
.
label
,
axis
=
2
)
ce_loss
=
fluid
.
layers
.
cross_entropy
(
input
=
self
.
output
,
label
=
labels
)
ce_loss
=
fluid
.
layers
.
cross_entropy
(
input
=
self
.
outputs
[
0
],
label
=
labels
)
loss
=
fluid
.
layers
.
mean
(
x
=
ce_loss
)
return
loss
...
...
@@ -865,7 +869,7 @@ class SequenceLabelTask(BasicTask):
return
[
metric
.
name
for
metric
in
self
.
metrics
]
+
[
self
.
loss
.
name
]
elif
self
.
is_predict_phase
:
return
[
self
.
ret_infers
.
name
]
+
[
self
.
seq_len
.
name
]
return
[
self
.
output
.
name
]
return
[
output
.
name
for
output
in
self
.
outputs
]
class
MultiLabelClassifierTask
(
ClassifierTask
):
...
...
@@ -928,7 +932,7 @@ class MultiLabelClassifierTask(ClassifierTask):
label_split
=
fluid
.
layers
.
split
(
self
.
label
,
self
.
num_classes
,
dim
=-
1
)
total_loss
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.0
,
dtype
=
'float64'
)
for
index
,
probs
in
enumerate
(
self
.
output
):
for
index
,
probs
in
enumerate
(
self
.
output
s
):
ce_loss
=
fluid
.
layers
.
cross_entropy
(
input
=
probs
,
label
=
label_split
[
index
])
total_loss
+=
fluid
.
layers
.
reduce_sum
(
ce_loss
)
...
...
@@ -939,7 +943,7 @@ class MultiLabelClassifierTask(ClassifierTask):
label_split
=
fluid
.
layers
.
split
(
self
.
label
,
self
.
num_classes
,
dim
=-
1
)
# metrics change to auc of every class
eval_list
=
[]
for
index
,
probs
in
enumerate
(
self
.
output
):
for
index
,
probs
in
enumerate
(
self
.
output
s
):
current_auc
,
_
,
_
=
fluid
.
layers
.
auc
(
input
=
probs
,
label
=
label_split
[
index
])
eval_list
.
append
(
current_auc
)
...
...
@@ -1015,4 +1019,4 @@ class MultiLabelClassifierTask(ClassifierTask):
def
fetch_list
(
self
):
if
self
.
is_train_phase
or
self
.
is_test_phase
:
return
[
metric
.
name
for
metric
in
self
.
metrics
]
+
[
self
.
loss
.
name
]
return
self
.
output
return
self
.
output
s
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录