Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
docs
提交
e69ef85d
D
docs
项目概览
MindSpore
/
docs
通知
4
Star
2
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e69ef85d
编写于
7月 24, 2020
作者:
G
gengdongjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify resnet50 for cloud train performance
上级
c232a04e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
4 addition
and
2 deletion
+4
-2
tutorials/tutorial_code/sample_for_cloud/resnet50_train.py
tutorials/tutorial_code/sample_for_cloud/resnet50_train.py
+4
-2
未找到文件。
tutorials/tutorial_code/sample_for_cloud/resnet50_train.py
浏览文件 @
e69ef85d
...
@@ -27,6 +27,7 @@ from mindspore.nn.loss import SoftmaxCrossEntropyWithLogits
...
@@ -27,6 +27,7 @@ from mindspore.nn.loss import SoftmaxCrossEntropyWithLogits
from
mindspore.train.model
import
Model
,
ParallelMode
from
mindspore.train.model
import
Model
,
ParallelMode
from
mindspore.train.callback
import
Callback
,
LossMonitor
from
mindspore.train.callback
import
Callback
,
LossMonitor
from
mindspore.train.loss_scale_manager
import
FixedLossScaleManager
from
mindspore.train.loss_scale_manager
import
FixedLossScaleManager
from
mindspore.communication.management
import
init
import
mindspore.dataset.engine
as
de
import
mindspore.dataset.engine
as
de
from
dataset
import
create_dataset
,
device_id
,
device_num
from
dataset
import
create_dataset
,
device_id
,
device_num
...
@@ -121,6 +122,7 @@ def resnet50_train(args_opt):
...
@@ -121,6 +122,7 @@ def resnet50_train(args_opt):
context
.
set_auto_parallel_context
(
device_num
=
device_num
,
context
.
set_auto_parallel_context
(
device_num
=
device_num
,
parallel_mode
=
ParallelMode
.
DATA_PARALLEL
,
parallel_mode
=
ParallelMode
.
DATA_PARALLEL
,
mirror_mean
=
True
)
mirror_mean
=
True
)
init
()
local_data_path
=
os
.
path
.
join
(
local_data_path
,
str
(
device_id
))
local_data_path
=
os
.
path
.
join
(
local_data_path
,
str
(
device_id
))
# data download
# data download
...
@@ -138,12 +140,12 @@ def resnet50_train(args_opt):
...
@@ -138,12 +140,12 @@ def resnet50_train(args_opt):
# create model
# create model
net
=
resnet50
(
class_num
=
class_num
)
net
=
resnet50
(
class_num
=
class_num
)
loss
=
SoftmaxCrossEntropyWithLogits
(
sparse
=
True
)
loss
=
SoftmaxCrossEntropyWithLogits
(
sparse
=
True
,
reduction
=
'mean'
)
lr
=
Tensor
(
get_lr
(
global_step
=
0
,
total_epochs
=
epoch_size
,
steps_per_epoch
=
train_step_size
))
lr
=
Tensor
(
get_lr
(
global_step
=
0
,
total_epochs
=
epoch_size
,
steps_per_epoch
=
train_step_size
))
opt
=
Momentum
(
net
.
trainable_params
(),
lr
,
momentum
=
0.9
,
weight_decay
=
1e-4
,
loss_scale
=
loss_scale_num
)
opt
=
Momentum
(
net
.
trainable_params
(),
lr
,
momentum
=
0.9
,
weight_decay
=
1e-4
,
loss_scale
=
loss_scale_num
)
loss_scale
=
FixedLossScaleManager
(
loss_scale_num
,
False
)
loss_scale
=
FixedLossScaleManager
(
loss_scale_num
,
False
)
model
=
Model
(
net
,
loss_fn
=
loss
,
optimizer
=
opt
,
loss_scale_manager
=
loss_scale
,
metrics
=
{
'acc'
})
model
=
Model
(
net
,
amp_level
=
"O2"
,
keep_batchnorm_fp32
=
False
,
loss_fn
=
loss
,
optimizer
=
opt
,
loss_scale_manager
=
loss_scale
,
metrics
=
{
'acc'
})
# define performance callback to show ips and loss callback to show loss for every epoch
# define performance callback to show ips and loss callback to show loss for every epoch
performance_cb
=
PerformanceCallback
(
batch_size
)
performance_cb
=
PerformanceCallback
(
batch_size
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录