Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
122c9bc7
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
122c9bc7
编写于
4月 29, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
!833 remove hccl seeting in mobilenetv2 eval script
Merge pull request !833 from wandongdong/master
上级
728345fd
0d7eb2a0
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
41 addition
and
6 deletion
+41
-6
example/mobilenetv2_imagenet2012/config.py
example/mobilenetv2_imagenet2012/config.py
+1
-0
example/mobilenetv2_imagenet2012/dataset.py
example/mobilenetv2_imagenet2012/dataset.py
+2
-2
example/mobilenetv2_imagenet2012/eval.py
example/mobilenetv2_imagenet2012/eval.py
+0
-2
example/mobilenetv2_imagenet2012/train.py
example/mobilenetv2_imagenet2012/train.py
+38
-2
未找到文件。
example/mobilenetv2_imagenet2012/config.py
浏览文件 @
122c9bc7
...
...
@@ -27,6 +27,7 @@ config = ed({
"lr"
:
0.4
,
"momentum"
:
0.9
,
"weight_decay"
:
4e-5
,
"label_smooth"
:
0.1
,
"loss_scale"
:
1024
,
"save_checkpoint"
:
True
,
"save_checkpoint_epochs"
:
1
,
...
...
example/mobilenetv2_imagenet2012/dataset.py
浏览文件 @
122c9bc7
...
...
@@ -53,8 +53,8 @@ def create_dataset(dataset_path, do_train, repeat_num=1, batch_size=32):
# define map operations
decode_op
=
C
.
Decode
()
resize_crop_op
=
C
.
RandomResizedCrop
(
resize_height
,
scale
=
(
0.
2
,
1.0
))
horizontal_flip_op
=
C
.
RandomHorizontalFlip
()
resize_crop_op
=
C
.
RandomResizedCrop
(
resize_height
,
scale
=
(
0.
08
,
1.0
),
ratio
=
(
0.75
,
1.333
))
horizontal_flip_op
=
C
.
RandomHorizontalFlip
(
prob
=
0.5
)
resize_op
=
C
.
Resize
((
256
,
256
))
center_crop
=
C
.
CenterCrop
(
resize_width
)
...
...
example/mobilenetv2_imagenet2012/eval.py
浏览文件 @
122c9bc7
...
...
@@ -38,8 +38,6 @@ context.set_context(enable_loop_sink=True)
context
.
set_context
(
enable_mem_reuse
=
True
)
if
__name__
==
'__main__'
:
context
.
set_context
(
enable_hccl
=
False
)
loss
=
SoftmaxCrossEntropyWithLogits
(
is_grad
=
False
,
sparse
=
True
,
reduction
=
'mean'
)
net
=
mobilenet_v2
()
...
...
example/mobilenetv2_imagenet2012/train.py
浏览文件 @
122c9bc7
...
...
@@ -28,6 +28,10 @@ from mindspore.model_zoo.mobilenet import mobilenet_v2
from
mindspore.parallel._auto_parallel_context
import
auto_parallel_context
from
mindspore.nn.optim.momentum
import
Momentum
from
mindspore.nn.loss
import
SoftmaxCrossEntropyWithLogits
from
mindspore.nn.loss.loss
import
_Loss
from
mindspore.ops
import
operations
as
P
from
mindspore.ops
import
functional
as
F
from
mindspore.common
import
dtype
as
mstype
from
mindspore.train.model
import
Model
,
ParallelMode
...
...
@@ -54,6 +58,35 @@ context.set_context(enable_task_sink=True)
context
.
set_context
(
enable_loop_sink
=
True
)
context
.
set_context
(
enable_mem_reuse
=
True
)
class
CrossEntropyWithLabelSmooth
(
_Loss
):
"""
CrossEntropyWith LabelSmooth.
Args:
smooth_factor (float): smooth factor, default=0.
num_classes (int): num classes
Returns:
None.
Examples:
>>> CrossEntropyWithLabelSmooth(smooth_factor=0., num_classes=1000)
"""
def
__init__
(
self
,
smooth_factor
=
0.
,
num_classes
=
1000
):
super
(
CrossEntropyWithLabelSmooth
,
self
).
__init__
()
self
.
onehot
=
P
.
OneHot
()
self
.
on_value
=
Tensor
(
1.0
-
smooth_factor
,
mstype
.
float32
)
self
.
off_value
=
Tensor
(
1.0
*
smooth_factor
/
(
num_classes
-
1
),
mstype
.
float32
)
self
.
ce
=
nn
.
SoftmaxCrossEntropyWithLogits
()
self
.
mean
=
P
.
ReduceMean
(
False
)
self
.
cast
=
P
.
Cast
()
def
construct
(
self
,
logit
,
label
):
one_hot_label
=
self
.
onehot
(
self
.
cast
(
label
,
mstype
.
int32
),
F
.
shape
(
logit
)[
1
],
self
.
on_value
,
self
.
off_value
)
out_loss
=
self
.
ce
(
logit
,
one_hot_label
)
out_loss
=
self
.
mean
(
out_loss
,
0
)
return
out_loss
class
Monitor
(
Callback
):
"""
...
...
@@ -63,7 +96,7 @@ class Monitor(Callback):
lr_init (numpy array): train lr
Returns:
None
.
None
Examples:
>>> Monitor(100,lr_init=Tensor([0.05]*100).asnumpy())
...
...
@@ -122,6 +155,9 @@ if __name__ == '__main__':
for
_
,
cell
in
net
.
cells_and_names
():
if
isinstance
(
cell
,
nn
.
Dense
):
cell
.
add_flags_recursive
(
fp32
=
True
)
if
config
.
label_smooth
>
0
:
loss
=
CrossEntropyWithLabelSmooth
(
smooth_factor
=
config
.
label_smooth
,
num_classes
=
config
.
num_classes
)
else
:
loss
=
SoftmaxCrossEntropyWithLogits
(
is_grad
=
False
,
sparse
=
True
,
reduction
=
'mean'
)
print
(
"train args: "
,
args_opt
,
"
\n
cfg: "
,
config
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录