Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
38b81892
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
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看板
提交
38b81892
编写于
6月 25, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update task to support multi label
上级
d74fbdea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
15 deletion
+19
-15
paddlehub/finetune/task.py
paddlehub/finetune/task.py
+19
-15
未找到文件。
paddlehub/finetune/task.py
浏览文件 @
38b81892
...
...
@@ -74,7 +74,7 @@ class RunEnv(object):
self
.
py_reader
=
None
self
.
reader
=
None
self
.
loss
=
None
self
.
label
=
None
self
.
label
s
=
None
self
.
metrics
=
None
self
.
is_inititalized
=
False
self
.
UNG
=
copy
.
deepcopy
(
fluid
.
unique_name
.
generator
)
...
...
@@ -183,7 +183,7 @@ class BasicTask(object):
with
fluid
.
unique_name
.
guard
(
self
.
env
.
UNG
):
self
.
env
.
outputs
=
self
.
_build_net
()
if
self
.
is_train_phase
or
self
.
is_test_phase
:
self
.
env
.
label
=
self
.
_add_label
()
self
.
env
.
label
s
=
self
.
_add_label
()
self
.
env
.
loss
=
self
.
_add_loss
()
self
.
env
.
metrics
=
self
.
_add_metrics
()
...
...
@@ -366,13 +366,13 @@ class BasicTask(object):
return
self
.
env
.
loss
@
property
def
label
(
self
):
def
label
s
(
self
):
if
self
.
is_predict_phase
:
raise
RuntimeError
()
if
not
self
.
env
.
is_inititalized
:
self
.
_build_env
()
return
self
.
env
.
label
return
self
.
env
.
label
s
@
property
def
outputs
(
self
):
...
...
@@ -397,7 +397,7 @@ class BasicTask(object):
def
feed_list
(
self
):
feed_list
=
[
varname
for
varname
in
self
.
_base_feed_list
]
if
self
.
is_train_phase
or
self
.
is_test_phase
:
feed_list
+=
[
self
.
label
.
name
]
feed_list
+=
[
label
.
name
for
label
in
self
.
labels
]
return
feed_list
@
property
...
...
@@ -689,15 +689,17 @@ class ClassifierTask(BasicTask):
return
[
logits
]
def
_add_label
(
self
):
return
fluid
.
layers
.
data
(
name
=
"label"
,
dtype
=
"int64"
,
shape
=
[
1
])
return
[
fluid
.
layers
.
data
(
name
=
"label"
,
dtype
=
"int64"
,
shape
=
[
1
])]
def
_add_loss
(
self
):
ce_loss
=
fluid
.
layers
.
cross_entropy
(
input
=
self
.
outputs
[
0
],
label
=
self
.
label
)
input
=
self
.
outputs
[
0
],
label
=
self
.
label
s
[
0
]
)
return
fluid
.
layers
.
mean
(
x
=
ce_loss
)
def
_add_metrics
(
self
):
return
[
fluid
.
layers
.
accuracy
(
input
=
self
.
outputs
[
0
],
label
=
self
.
label
)]
return
[
fluid
.
layers
.
accuracy
(
input
=
self
.
outputs
[
0
],
label
=
self
.
labels
[
0
])
]
def
_build_env_end_event
(
self
):
with
self
.
log_writer
.
mode
(
self
.
phase
)
as
logw
:
...
...
@@ -854,17 +856,17 @@ class SequenceLabelTask(BasicTask):
def
_add_label
(
self
):
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
self
.
max_seq_len
,
1
],
dtype
=
'int64'
)
return
label
return
[
label
]
def
_add_loss
(
self
):
labels
=
fluid
.
layers
.
flatten
(
self
.
label
,
axis
=
2
)
labels
=
fluid
.
layers
.
flatten
(
self
.
label
s
[
0
]
,
axis
=
2
)
ce_loss
=
fluid
.
layers
.
cross_entropy
(
input
=
self
.
outputs
[
0
],
label
=
labels
)
loss
=
fluid
.
layers
.
mean
(
x
=
ce_loss
)
return
loss
def
_add_metrics
(
self
):
self
.
ret_labels
=
fluid
.
layers
.
reshape
(
x
=
self
.
label
,
shape
=
[
-
1
,
1
])
self
.
ret_labels
=
fluid
.
layers
.
reshape
(
x
=
self
.
label
s
[
0
]
,
shape
=
[
-
1
,
1
])
return
[
self
.
ret_labels
,
self
.
ret_infers
,
self
.
seq_len
]
def
_build_env_end_event
(
self
):
...
...
@@ -938,7 +940,7 @@ class SequenceLabelTask(BasicTask):
def
feed_list
(
self
):
feed_list
=
[
varname
for
varname
in
self
.
_base_feed_list
]
if
self
.
is_train_phase
or
self
.
is_test_phase
:
feed_list
+=
[
self
.
label
.
name
,
self
.
seq_len
.
name
]
feed_list
+=
[
self
.
label
s
[
0
]
.
name
,
self
.
seq_len
.
name
]
else
:
feed_list
+=
[
self
.
seq_len
.
name
]
return
feed_list
...
...
@@ -1006,10 +1008,11 @@ class MultiLabelClassifierTask(ClassifierTask):
def
_add_label
(
self
):
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
self
.
num_classes
],
dtype
=
'int64'
)
return
label
return
[
label
]
def
_add_loss
(
self
):
label_split
=
fluid
.
layers
.
split
(
self
.
label
,
self
.
num_classes
,
dim
=-
1
)
label_split
=
fluid
.
layers
.
split
(
self
.
labels
[
0
],
self
.
num_classes
,
dim
=-
1
)
total_loss
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.0
,
dtype
=
'float64'
)
for
index
,
probs
in
enumerate
(
self
.
outputs
):
...
...
@@ -1020,7 +1023,8 @@ class MultiLabelClassifierTask(ClassifierTask):
return
loss
def
_add_metrics
(
self
):
label_split
=
fluid
.
layers
.
split
(
self
.
label
,
self
.
num_classes
,
dim
=-
1
)
label_split
=
fluid
.
layers
.
split
(
self
.
labels
[
0
],
self
.
num_classes
,
dim
=-
1
)
# metrics change to auc of every class
eval_list
=
[]
for
index
,
probs
in
enumerate
(
self
.
outputs
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录