Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
6a0dce8a
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
116
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6a0dce8a
编写于
6月 29, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support label smooth for dyg
上级
be35b7cc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
29 deletion
+47
-29
ppcls/modeling/architectures/__init__.py
ppcls/modeling/architectures/__init__.py
+1
-0
ppcls/modeling/architectures/dpn.py
ppcls/modeling/architectures/dpn.py
+1
-1
tools/program.py
tools/program.py
+45
-28
未找到文件。
ppcls/modeling/architectures/__init__.py
浏览文件 @
6a0dce8a
...
...
@@ -13,3 +13,4 @@
# limitations under the License.
from
.resnet_name
import
*
from
.dpn
import
DPN68
ppcls/modeling/architectures/dpn.py
浏览文件 @
6a0dce8a
...
...
@@ -408,4 +408,4 @@ def DPN107():
def
DPN131
():
model
=
DPN
(
layers
=
131
)
return
model
return
model
\ No newline at end of file
tools/program.py
浏览文件 @
6a0dce8a
...
...
@@ -51,9 +51,7 @@ def create_dataloader():
trainer_num
=
int
(
os
.
environ
.
get
(
'PADDLE_TRAINERS_NUM'
,
1
))
capacity
=
64
if
trainer_num
<=
1
else
8
dataloader
=
fluid
.
io
.
DataLoader
.
from_generator
(
capacity
=
capacity
,
use_double_buffer
=
True
,
iterable
=
True
)
capacity
=
capacity
,
use_double_buffer
=
True
,
iterable
=
True
)
return
dataloader
...
...
@@ -76,8 +74,8 @@ def create_model(architecture, classes_num):
return
architectures
.
__dict__
[
name
](
class_dim
=
classes_num
,
**
params
)
def
create_loss
(
out
,
label
,
def
create_loss
(
feeds
,
out
,
architecture
,
classes_num
=
1000
,
epsilon
=
None
,
...
...
@@ -106,7 +104,7 @@ def create_loss(out,
if
architecture
[
"name"
]
==
"GoogLeNet"
:
assert
len
(
out
)
==
3
,
"GoogLeNet should have 3 outputs"
loss
=
GoogLeNetLoss
(
class_dim
=
classes_num
,
epsilon
=
epsilon
)
return
loss
(
out
[
0
],
out
[
1
],
out
[
2
],
label
)
return
loss
(
out
[
0
],
out
[
1
],
out
[
2
],
feeds
[
"label"
]
)
if
use_distillation
:
assert
len
(
out
)
==
2
,
(
"distillation output length must be 2, "
...
...
@@ -116,14 +114,13 @@ def create_loss(out,
if
use_mix
:
loss
=
MixCELoss
(
class_dim
=
classes_num
,
epsilon
=
epsilon
)
raise
NotImplementedError
#feed_y_a = feeds['feed_y_a']
#feed_y_b = feeds['feed_y_b']
#feed_lam = feeds['feed_lam']
#return loss(out, feed_y_a, feed_y_b, feed_lam)
feed_y_a
=
feeds
[
'y_a'
]
feed_y_b
=
feeds
[
'y_b'
]
feed_lam
=
feeds
[
'lam'
]
return
loss
(
out
,
feed_y_a
,
feed_y_b
,
feed_lam
)
else
:
loss
=
CELoss
(
class_dim
=
classes_num
,
epsilon
=
epsilon
)
return
loss
(
out
,
label
)
return
loss
(
out
,
feeds
[
"label"
]
)
def
create_metric
(
out
,
...
...
@@ -166,8 +163,9 @@ def create_metric(out,
return
fetchs
def
create_fetchs
(
out
,
label
,
def
create_fetchs
(
feeds
,
out
,
config
,
architecture
,
topk
=
5
,
classes_num
=
1000
,
...
...
@@ -193,11 +191,11 @@ def create_fetchs(out,
fetchs(dict): dict of model outputs(included loss and measures)
"""
fetchs
=
OrderedDict
()
fetchs
[
'loss'
]
=
create_loss
(
out
,
label
,
architecture
,
classes_num
,
epsilon
,
use_mix
,
use_distillation
)
fetchs
[
'loss'
]
=
create_loss
(
feeds
,
out
,
architecture
,
classes_num
,
epsilon
,
use_mix
,
use_distillation
)
if
not
use_mix
:
metric
=
create_metric
(
out
,
label
,
architecture
,
topk
,
classes_num
,
use_distillation
)
metric
=
create_metric
(
out
,
feeds
[
"label"
],
architecture
,
topk
,
classes_num
,
use_distillation
)
fetchs
.
update
(
metric
)
return
fetchs
...
...
@@ -278,7 +276,7 @@ def mixed_precision_optimizer(config, optimizer):
return
optimizer
def
compute
(
config
,
out
,
label
,
mode
=
'train'
):
def
compute
(
feeds
,
net
,
config
,
mode
=
'train'
):
"""
Build a program using a model and an optimizer
1. create feeds
...
...
@@ -297,9 +295,11 @@ def compute(config, out, label, mode='train'):
dataloader(): a bridge between the model and the data
fetchs(dict): dict of model outputs(included loss and measures)
"""
out
=
net
(
feeds
[
"image"
])
fetchs
=
create_fetchs
(
feeds
,
out
,
label
,
config
,
config
.
ARCHITECTURE
,
config
.
topk
,
config
.
classes_num
,
...
...
@@ -310,6 +310,20 @@ def compute(config, out, label, mode='train'):
return
fetchs
def
create_feeds
(
batch
,
use_mix
):
if
use_mix
:
image
=
batch
[
0
]
y_a
=
to_variable
(
batch
[
1
].
numpy
().
astype
(
"int64"
).
reshape
(
-
1
,
1
))
y_b
=
to_variable
(
batch
[
2
].
numpy
().
astype
(
"int64"
).
reshape
(
-
1
,
1
))
lam
=
to_variable
(
batch
[
3
].
numpy
().
astype
(
"float32"
).
reshape
(
-
1
,
1
))
feeds
=
{
"image"
:
image
,
"y_a"
:
y_a
,
"y_b"
:
y_b
,
"lam"
:
lam
}
else
:
image
=
batch
[
0
]
label
=
to_variable
(
batch
[
1
].
numpy
().
astype
(
'int64'
).
reshape
(
-
1
,
1
))
feeds
=
{
"image"
:
image
,
"label"
:
label
}
return
feeds
def
run
(
dataloader
,
config
,
net
,
optimizer
=
None
,
epoch
=
0
,
mode
=
'train'
):
"""
Feed data to the model and fetch the measures and loss
...
...
@@ -329,14 +343,16 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'):
(
"loss"
,
AverageMeter
(
'loss'
,
'7.4f'
)),
(
"top1"
,
AverageMeter
(
'top1'
,
'.4f'
)),
(
topk_name
,
AverageMeter
(
topk_name
,
'.4f'
)),
(
"lr"
,
AverageMeter
(
'lr'
,
'f'
,
need_avg
=
False
)),
(
"lr"
,
AverageMeter
(
'lr'
,
'f'
,
need_avg
=
False
)),
(
"batch_time"
,
AverageMeter
(
'elapse'
,
'.3f'
)),
])
tic
=
time
.
time
()
for
idx
,
(
img
,
label
)
in
enumerate
(
dataloader
()):
label
=
to_variable
(
label
.
numpy
().
astype
(
'int64'
).
reshape
(
-
1
,
1
))
fetchs
=
compute
(
config
,
net
(
img
),
label
,
mode
)
for
idx
,
batch
in
enumerate
(
dataloader
()):
bs
=
len
(
batch
[
0
])
feeds
=
create_feeds
(
batch
,
config
.
get
(
"use_mix"
,
False
))
fetchs
=
compute
(
feeds
,
net
,
config
,
mode
)
if
mode
==
'train'
:
avg_loss
=
net
.
scale_loss
(
fetchs
[
'loss'
])
avg_loss
.
backward
()
...
...
@@ -345,10 +361,10 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'):
optimizer
.
minimize
(
avg_loss
)
net
.
clear_gradients
()
metric_list
[
'lr'
].
update
(
optimizer
.
_global_learning_rate
().
numpy
()[
0
],
len
(
img
)
)
optimizer
.
_global_learning_rate
().
numpy
()[
0
],
bs
)
for
name
,
fetch
in
fetchs
.
items
():
metric_list
[
name
].
update
(
fetch
.
numpy
()[
0
],
len
(
img
)
)
metric_list
[
name
].
update
(
fetch
.
numpy
()[
0
],
bs
)
metric_list
[
'batch_time'
].
update
(
time
.
time
()
-
tic
)
tic
=
time
.
time
()
...
...
@@ -365,7 +381,8 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'):
logger
.
coloring
(
step_str
,
"PURPLE"
),
logger
.
coloring
(
fetchs_str
,
'OKGREEN'
)))
end_str
=
' '
.
join
([
str
(
m
.
mean
)
for
m
in
metric_list
.
values
()]
+
[
metric_list
[
'batch_time'
].
total
])
end_str
=
' '
.
join
([
str
(
m
.
mean
)
for
m
in
metric_list
.
values
()]
+
[
metric_list
[
'batch_time'
].
total
])
if
mode
==
'eval'
:
logger
.
info
(
"END {:s} {:s}s"
.
format
(
mode
,
end_str
))
else
:
...
...
@@ -378,4 +395,4 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'):
# return top1_acc in order to save the best model
if
mode
==
'valid'
:
return
metric_list
[
'top1'
].
avg
\ No newline at end of file
return
metric_list
[
'top1'
].
avg
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录