Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
7ed80c52
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
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看板
提交
7ed80c52
编写于
9月 13, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix program
上级
d609a81d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
13 addition
and
15 deletion
+13
-15
ppcls/modeling/architectures/resnet.py
ppcls/modeling/architectures/resnet.py
+0
-1
tools/program.py
tools/program.py
+13
-14
未找到文件。
ppcls/modeling/architectures/resnet.py
浏览文件 @
7ed80c52
...
...
@@ -19,7 +19,6 @@ from __future__ import print_function
import
numpy
as
np
import
paddle
from
paddle
import
ParamAttr
# from paddle.fluid.param_attr import ParamAttr
import
paddle.nn
as
nn
from
paddle.nn
import
Conv2d
,
Pool2D
,
BatchNorm
,
Linear
,
Dropout
...
...
tools/program.py
浏览文件 @
7ed80c52
...
...
@@ -18,11 +18,12 @@ from __future__ import print_function
import
os
import
time
from
collections
import
OrderedDict
import
paddle
import
paddle.fluid
as
fluid
from
paddle
import
to_tensor
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
ppcls.optimizer
import
LearningRateBuilder
from
ppcls.optimizer
import
OptimizerBuilder
...
...
@@ -34,8 +35,6 @@ from ppcls.modeling.loss import GoogLeNetLoss
from
ppcls.utils.misc
import
AverageMeter
from
ppcls.utils
import
logger
from
paddle.fluid.dygraph.base
import
to_variable
def
create_dataloader
():
"""
...
...
@@ -45,11 +44,11 @@ def create_dataloader():
feeds(dict): dict of model input variables
Returns:
dataloader(
fluid
dataloader):
dataloader(
paddle
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
(
dataloader
=
paddle
.
io
.
DataLoader
.
from_generator
(
capacity
=
capacity
,
use_double_buffer
=
True
,
iterable
=
True
)
return
dataloader
...
...
@@ -149,15 +148,15 @@ def create_metric(out,
# just need student label to get metrics
if
use_distillation
:
out
=
out
[
1
]
softmax_out
=
fluid
.
layers
.
softmax
(
out
,
use_cudnn
=
False
)
softmax_out
=
F
.
softmax
(
out
)
fetchs
=
OrderedDict
()
# set top1 to fetchs
top1
=
fluid
.
layers
.
accuracy
(
softmax_out
,
label
=
label
,
k
=
1
)
top1
=
paddle
.
metric
.
accuracy
(
softmax_out
,
label
=
label
,
k
=
1
)
fetchs
[
'top1'
]
=
top1
# set topk to fetchs
k
=
min
(
topk
,
classes_num
)
topk
=
fluid
.
layers
.
accuracy
(
softmax_out
,
label
=
label
,
k
=
k
)
topk
=
paddle
.
metric
.
accuracy
(
softmax_out
,
label
=
label
,
k
=
k
)
topk_name
=
'top{}'
.
format
(
k
)
fetchs
[
topk_name
]
=
topk
...
...
@@ -244,12 +243,12 @@ def create_optimizer(config, parameter_list=None):
def
create_feeds
(
batch
,
use_mix
):
image
=
batch
[
0
]
if
use_mix
:
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
))
y_a
=
to_
tensor
(
batch
[
1
].
numpy
().
astype
(
"int64"
).
reshape
(
-
1
,
1
))
y_b
=
to_
tensor
(
batch
[
2
].
numpy
().
astype
(
"int64"
).
reshape
(
-
1
,
1
))
lam
=
to_
tensor
(
batch
[
3
].
numpy
().
astype
(
"float32"
).
reshape
(
-
1
,
1
))
feeds
=
{
"image"
:
image
,
"y_a"
:
y_a
,
"y_b"
:
y_b
,
"lam"
:
lam
}
else
:
label
=
to_
variable
(
batch
[
1
].
numpy
().
astype
(
'int64'
).
reshape
(
-
1
,
1
))
label
=
to_
tensor
(
batch
[
1
].
numpy
().
astype
(
'int64'
).
reshape
(
-
1
,
1
))
feeds
=
{
"image"
:
image
,
"label"
:
label
}
return
feeds
...
...
@@ -259,7 +258,7 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'):
Feed data to the model and fetch the measures and loss
Args:
dataloader(
fluid
dataloader):
dataloader(
paddle
dataloader):
exe():
program():
fetchs(dict): dict of measures and the loss
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录