Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
dad2dab0
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看板
未验证
提交
dad2dab0
编写于
1月 27, 2021
作者:
L
littletomatodonkey
提交者:
GitHub
1月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add device num for xpu (#581)
* add device num for xpu * fix vgg
上级
d2bd6ca8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
18 deletion
+32
-18
ppcls/data/reader.py
ppcls/data/reader.py
+17
-8
ppcls/modeling/architectures/vgg.py
ppcls/modeling/architectures/vgg.py
+14
-9
tools/program.py
tools/program.py
+1
-1
未找到文件。
ppcls/data/reader.py
浏览文件 @
dad2dab0
...
...
@@ -25,7 +25,7 @@ from . import imaug
from
.imaug
import
transform
from
ppcls.utils
import
logger
trainers_num
=
int
(
os
.
environ
.
get
(
'PADDLE_TRAINERS_NUM'
,
0
))
trainers_num
=
int
(
os
.
environ
.
get
(
'PADDLE_TRAINERS_NUM'
,
1
))
trainer_id
=
int
(
os
.
environ
.
get
(
"PADDLE_TRAINER_ID"
,
0
))
...
...
@@ -257,6 +257,9 @@ class Reader:
raise
ModeException
(
mode
=
mode
)
self
.
use_gpu
=
config
.
get
(
"use_gpu"
,
True
)
self
.
use_xpu
=
config
.
get
(
"use_xpu"
,
False
)
self
.
is_distributed
=
config
.
get
(
"is_distributed"
,
True
)
use_mix
=
config
.
get
(
'use_mix'
)
self
.
params
[
'mode'
]
=
mode
if
seed
is
not
None
:
...
...
@@ -265,14 +268,20 @@ class Reader:
if
use_mix
and
mode
==
"train"
:
self
.
batch_ops
=
create_operators
(
self
.
params
[
'mix'
])
def
get_device_num
(
self
):
if
self
.
is_distributed
:
device_num
=
trainers_num
elif
self
.
use_gpu
:
device_num
=
fluid
.
core
.
get_cuda_device_count
()
elif
self
.
use_xpu
:
xpus
=
os
.
environ
.
get
(
"FLAGS_selected_xpus"
,
'1'
)
device_num
=
len
(
xpus
.
split
(
','
))
else
:
device_num
=
int
(
os
.
environ
.
get
(
'CPU_NUM'
,
1
))
return
device_num
def
__call__
(
self
):
device_num
=
trainers_num
# non-distributed launch
if
trainers_num
<=
0
:
if
self
.
use_gpu
:
device_num
=
fluid
.
core
.
get_cuda_device_count
()
else
:
device_num
=
int
(
os
.
environ
.
get
(
'CPU_NUM'
,
1
))
device_num
=
self
.
get_device_num
()
batch_size
=
int
(
self
.
params
[
'batch_size'
])
//
device_num
def
wrapper
():
...
...
ppcls/modeling/architectures/vgg.py
浏览文件 @
dad2dab0
...
...
@@ -23,8 +23,9 @@ __all__ = ["VGGNet", "VGG11", "VGG13", "VGG16", "VGG19"]
class
VGGNet
():
def
__init__
(
self
,
layers
=
16
):
def
__init__
(
self
,
layers
=
16
,
stop_grad_layers
=
0
,
**
args
):
self
.
layers
=
layers
self
.
stop_grad_layers
=
stop_grad_layers
def
net
(
self
,
input
,
class_dim
=
1000
):
layers
=
self
.
layers
...
...
@@ -44,6 +45,10 @@ class VGGNet():
conv4
=
self
.
conv_block
(
conv3
,
512
,
nums
[
3
],
name
=
"conv4_"
)
conv5
=
self
.
conv_block
(
conv4
,
512
,
nums
[
4
],
name
=
"conv5_"
)
for
idx
,
conv
in
enumerate
([
conv1
,
conv2
,
conv3
,
conv4
,
conv5
]):
if
self
.
stop_grad_layers
>=
idx
+
1
:
conv
.
stop_gradient
=
True
fc_dim
=
4096
fc_name
=
[
"fc6"
,
"fc7"
,
"fc8"
]
fc1
=
fluid
.
layers
.
fc
(
...
...
@@ -88,21 +93,21 @@ class VGGNet():
input
=
conv
,
pool_size
=
2
,
pool_type
=
'max'
,
pool_stride
=
2
)
def
VGG11
():
model
=
VGGNet
(
layers
=
11
)
def
VGG11
(
stop_grad_layers
=
0
,
**
args
):
model
=
VGGNet
(
layers
=
11
,
stop_grad_layers
=
stop_grad_layers
,
**
args
)
return
model
def
VGG13
():
model
=
VGGNet
(
layers
=
13
)
def
VGG13
(
stop_grad_layers
=
0
,
**
args
):
model
=
VGGNet
(
layers
=
13
,
stop_grad_layers
=
stop_grad_layers
,
**
args
)
return
model
def
VGG16
():
model
=
VGGNet
(
layers
=
16
)
def
VGG16
(
stop_grad_layers
=
0
,
**
args
):
model
=
VGGNet
(
layers
=
16
,
stop_grad_layers
=
stop_grad_layers
,
**
args
)
return
model
def
VGG19
():
model
=
VGGNet
(
layers
=
19
)
def
VGG19
(
stop_grad_layers
=
0
,
**
args
):
model
=
VGGNet
(
layers
=
19
,
stop_grad_layers
=
stop_grad_layers
,
**
args
)
return
model
tools/program.py
浏览文件 @
dad2dab0
...
...
@@ -282,6 +282,7 @@ def create_optimizer(config):
# create optimizer instance
opt_config
=
config
[
'OPTIMIZER'
]
opt
=
OptimizerBuilder
(
**
opt_config
)
return
opt
(
lr
)
...
...
@@ -305,7 +306,6 @@ def dist_optimizer(config, optimizer):
dist_strategy
.
fuse_all_reduce_ops
=
True
dist_strategy
.
exec_strategy
=
exec_strategy
optimizer
=
fleet
.
distributed_optimizer
(
optimizer
,
strategy
=
dist_strategy
)
return
optimizer
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录