Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
d3574301
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d3574301
编写于
5月 22, 2019
作者:
C
chengduozh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish code
上级
950fa5c6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
13 deletion
+23
-13
dygraph/dist_resnet/dist_train.py
dygraph/dist_resnet/dist_train.py
+23
-13
未找到文件。
dygraph/dist_resnet/dist_train.py
浏览文件 @
d3574301
...
...
@@ -195,27 +195,33 @@ class ResNet(fluid.dygraph.Layer):
return
y
,
acc1
,
acc5
def
init_data
(
batch_size
=
32
,
img_shape
=
[
3
,
224
,
224
],
label_range
=
9
):
assert
isinstance
(
img_shape
,
list
)
np
.
random
.
seed
(
5
)
input_shape
=
[
batch_size
]
+
img_shape
img
=
np
.
random
.
random
(
size
=
input_shape
).
astype
(
np
.
float32
)
label
=
np
.
array
([
1
for
_
in
range
(
batch_size
)]).
reshape
(
(
-
1
,
1
)).
astype
(
"int64"
)
#label = np.array(
# [np.random.randint(0, label_range) for _ in range(batch_size)]).reshape(
# (-1, 1)).astype("int64")
return
img
,
label
def
train_resnet
():
seed
=
90
place
=
fluid
.
CUDAPlace
(
dygraph
.
parallel
.
Env
().
dev_id
)
with
fluid
.
dygraph
.
guard
(
place
):
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
np
.
random
.
seed
(
seed
)
import
random
random
.
seed
=
seed
strategy
=
dygraph
.
parallel
.
prepare_context
()
resnet
=
ResNet
(
"dist_resnet"
,
class_dim
=
1000
)
strategy
=
dygraph
.
parallel
.
ParallelStrategy
()
strategy
.
nranks
=
dygraph
.
parallel
.
Env
().
nranks
strategy
.
local_rank
=
dygraph
.
parallel
.
Env
().
local_rank
strategy
.
trainer_endpoints
=
dygraph
.
parallel
.
Env
().
trainer_endpoints
strategy
.
current_endpoint
=
dygraph
.
parallel
.
Env
().
current_endpoint
resnet
=
dygraph
.
parallel
.
DataParallel
(
resnet
,
strategy
)
#if strategy.nranks > 1:
# dygraph.parallel.prepare_context(strategy)
optimizer
=
optimizer_setting
()
train_reader
=
paddle
.
batch
(
train
(
data_dir
=
"/imagenet/ImageNet_resize/"
,
...
...
@@ -225,6 +231,7 @@ def train_resnet():
drop_last
=
True
)
steps_per_epoch
=
int
(
total_images
/
strategy
.
nranks
/
batch_size
)
print
(
"steps per eoch: %d"
%
steps_per_epoch
)
for
eop
in
range
(
epoch
):
for
step_id
,
data
in
enumerate
(
train_reader
()):
if
step_id
==
steps_per_epoch
:
...
...
@@ -234,10 +241,13 @@ def train_resnet():
continue
s_time
=
time
.
time
()
dy_x_data
=
np
.
array
(
[
x
[
0
].
reshape
(
3
,
224
,
224
)
for
x
in
data
]).
astype
(
'float32'
)
y_data
=
np
.
array
([
x
[
1
]
for
x
in
data
]).
astype
(
'int64'
).
reshape
(
batch_size
,
1
)
#dy_x_data = np.array(
# [x[0].reshape(3, 224, 224) for x in data]).astype('float32')
#y_data = np.array([x[1] for x in data]).astype('int64').reshape(
# batch_size, 1)
dy_x_data
,
y_data
=
init_data
()
print
(
np
.
sum
(
dy_x_data
),
np
.
sum
(
y_data
))
img
=
to_variable
(
dy_x_data
)
label
=
to_variable
(
y_data
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录