Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pingzhuyan
mindspore
提交
e3a5a3b5
M
mindspore
项目概览
pingzhuyan
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
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,发现更多精彩内容 >>
提交
e3a5a3b5
编写于
5月 26, 2020
作者:
C
chenzomi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug for mobilenet in model_zoo
上级
b42ba6c4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
8 deletion
+22
-8
mindspore/model_zoo/mobilenetv2/src/dataset.py
mindspore/model_zoo/mobilenetv2/src/dataset.py
+3
-2
mindspore/model_zoo/mobilenetv2/train.py
mindspore/model_zoo/mobilenetv2/train.py
+7
-2
mindspore/model_zoo/mobilenetv3/eval.py
mindspore/model_zoo/mobilenetv3/eval.py
+3
-2
mindspore/model_zoo/mobilenetv3/src/dataset.py
mindspore/model_zoo/mobilenetv3/src/dataset.py
+3
-1
mindspore/model_zoo/mobilenetv3/train.py
mindspore/model_zoo/mobilenetv3/train.py
+6
-1
未找到文件。
mindspore/model_zoo/mobilenetv2/src/dataset.py
浏览文件 @
e3a5a3b5
...
...
@@ -21,7 +21,6 @@ import mindspore.dataset.engine as de
import
mindspore.dataset.transforms.vision.c_transforms
as
C
import
mindspore.dataset.transforms.c_transforms
as
C2
def
create_dataset
(
dataset_path
,
do_train
,
config
,
platform
,
repeat_num
=
1
,
batch_size
=
32
):
"""
create a train or eval dataset
...
...
@@ -44,7 +43,9 @@ def create_dataset(dataset_path, do_train, config, platform, repeat_num=1, batch
ds
=
de
.
ImageFolderDatasetV2
(
dataset_path
,
num_parallel_workers
=
8
,
shuffle
=
True
,
num_shards
=
rank_size
,
shard_id
=
rank_id
)
elif
platform
==
"GPU"
:
ds
=
de
.
ImageFolderDatasetV2
(
dataset_path
,
num_parallel_workers
=
8
,
shuffle
=
True
)
from
mindspore.communication.management
import
get_rank
,
get_group_size
ds
=
de
.
ImageFolderDatasetV2
(
dataset_path
,
num_parallel_workers
=
8
,
shuffle
=
True
,
num_shards
=
get_group_size
(),
shard_id
=
get_rank
())
else
:
raise
ValueError
(
"Unsupport platform."
)
...
...
mindspore/model_zoo/mobilenetv2/train.py
浏览文件 @
e3a5a3b5
...
...
@@ -32,7 +32,7 @@ from mindspore.train.model import Model, ParallelMode
from
mindspore.train.callback
import
ModelCheckpoint
,
CheckpointConfig
,
Callback
from
mindspore.train.loss_scale_manager
import
FixedLossScaleManager
from
mindspore.train.serialization
import
load_checkpoint
,
load_param_into_net
from
mindspore.communication.management
import
init
from
mindspore.communication.management
import
init
,
get_group_size
import
mindspore.dataset.engine
as
de
from
src.dataset
import
create_dataset
from
src.lr_generator
import
get_lr
...
...
@@ -157,6 +157,11 @@ if __name__ == '__main__':
# train on gpu
print
(
"train args: "
,
args_opt
,
"
\n
cfg: "
,
config_gpu
)
init
(
'nccl'
)
context
.
set_auto_parallel_context
(
parallel_mode
=
"data_parallel"
,
mirror_mean
=
True
,
device_num
=
get_group_size
())
# define net
net
=
mobilenet_v2
(
num_classes
=
config_gpu
.
num_classes
,
platform
=
"GPU"
)
# define loss
...
...
@@ -223,7 +228,7 @@ if __name__ == '__main__':
cell
.
to_float
(
mstype
.
float32
)
if
config_ascend
.
label_smooth
>
0
:
loss
=
CrossEntropyWithLabelSmooth
(
smooth_factor
=
config_ascend
.
label_smooth
,
num_classes
=
config
.
num_classes
)
smooth_factor
=
config_ascend
.
label_smooth
,
num_classes
=
config
_ascend
.
num_classes
)
else
:
loss
=
SoftmaxCrossEntropyWithLogits
(
is_grad
=
False
,
sparse
=
True
,
reduction
=
'mean'
)
...
...
mindspore/model_zoo/mobilenetv3/eval.py
浏览文件 @
e3a5a3b5
...
...
@@ -24,7 +24,8 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
from
mindspore.common
import
dtype
as
mstype
from
src.dataset
import
create_dataset
from
src.config
import
config_ascend
,
config_gpu
from
src.mobilenetV2
import
mobilenet_v2
from
src.mobilenetV3
import
mobilenet_v3_large
parser
=
argparse
.
ArgumentParser
(
description
=
'Image classification'
)
parser
.
add_argument
(
'--checkpoint_path'
,
type
=
str
,
default
=
None
,
help
=
'Checkpoint file path'
)
...
...
@@ -49,7 +50,7 @@ if __name__ == '__main__':
loss
=
nn
.
SoftmaxCrossEntropyWithLogits
(
is_grad
=
False
,
sparse
=
True
,
reduction
=
'mean'
)
net
=
mobilenet_v
2
(
num_classes
=
config_platform
.
num_classes
)
net
=
mobilenet_v
3_large
(
num_classes
=
config_platform
.
num_classes
)
if
args_opt
.
platform
==
"Ascend"
:
net
.
to_float
(
mstype
.
float16
)
...
...
mindspore/model_zoo/mobilenetv3/src/dataset.py
浏览文件 @
e3a5a3b5
...
...
@@ -44,7 +44,9 @@ def create_dataset(dataset_path, do_train, config, platform, repeat_num=1, batch
ds
=
de
.
ImageFolderDatasetV2
(
dataset_path
,
num_parallel_workers
=
8
,
shuffle
=
True
,
num_shards
=
rank_size
,
shard_id
=
rank_id
)
elif
platform
==
"GPU"
:
ds
=
de
.
ImageFolderDatasetV2
(
dataset_path
,
num_parallel_workers
=
8
,
shuffle
=
True
)
from
mindspore.communication.management
import
get_rank
,
get_group_size
ds
=
de
.
ImageFolderDatasetV2
(
dataset_path
,
num_parallel_workers
=
8
,
shuffle
=
True
,
num_shards
=
get_group_size
(),
shard_id
=
get_rank
())
else
:
raise
ValueError
(
"Unsupport platform."
)
...
...
mindspore/model_zoo/mobilenetv3/train.py
浏览文件 @
e3a5a3b5
...
...
@@ -33,7 +33,7 @@ from mindspore.train.callback import ModelCheckpoint, CheckpointConfig, Callback
from
mindspore.train.loss_scale_manager
import
FixedLossScaleManager
from
mindspore.train.serialization
import
load_checkpoint
,
load_param_into_net
import
mindspore.dataset.engine
as
de
from
mindspore.communication.management
import
init
from
mindspore.communication.management
import
init
,
get_group_size
from
src.dataset
import
create_dataset
from
src.lr_generator
import
get_lr
from
src.config
import
config_gpu
,
config_ascend
...
...
@@ -157,6 +157,11 @@ if __name__ == '__main__':
# train on gpu
print
(
"train args: "
,
args_opt
,
"
\n
cfg: "
,
config_gpu
)
init
(
'nccl'
)
context
.
set_auto_parallel_context
(
parallel_mode
=
"data_parallel"
,
mirror_mean
=
True
,
device_num
=
get_group_size
())
# define net
net
=
mobilenet_v3_large
(
num_classes
=
config_gpu
.
num_classes
)
# define loss
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录