Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
4e3fa200
M
mindspore
项目概览
magicwindyyd
/
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看板
提交
4e3fa200
编写于
7月 28, 2020
作者:
M
ms_yan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
repair problem in vgg16 cifar10 version
上级
7cb567eb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
21 addition
and
24 deletion
+21
-24
model_zoo/official/cv/vgg16/README.md
model_zoo/official/cv/vgg16/README.md
+4
-2
model_zoo/official/cv/vgg16/eval.py
model_zoo/official/cv/vgg16/eval.py
+13
-18
model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh
model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh
+1
-1
model_zoo/official/cv/vgg16/src/vgg.py
model_zoo/official/cv/vgg16/src/vgg.py
+1
-1
model_zoo/official/cv/vgg16/train.py
model_zoo/official/cv/vgg16/train.py
+2
-2
未找到文件。
model_zoo/official/cv/vgg16/README.md
浏览文件 @
4e3fa200
...
...
@@ -38,9 +38,11 @@ epcoh: 2 step: 781, loss is 1.827582
### Evaluation
-
Do eval as follows, need to specify dataset type as "cifar10" or "imagenet2012"
```
python eval.py --data_path=your_data_path --d
evice_id=6 --checkpoint_path
=./train_vgg_cifar10-70-781.ckpt > out.eval.log 2>&1 &
python eval.py --data_path=your_data_path --d
ataset="cifar10" --pre_trained
=./train_vgg_cifar10-70-781.ckpt > out.eval.log 2>&1 &
```
-
If the using dataset is
The above python command will run in the background, you can view the results through the file
`out.eval.log`
.
You will get the accuracy as following:
...
...
@@ -93,7 +95,7 @@ parameters/options:
--device_target the evaluation backend type, default is Ascend.
--data_path the storage path of datasetd
--device_id the device which used to evaluate model.
--
checkpoint_path
the checkpoint file path used to evaluate model.
--
pre_trained
the checkpoint file path used to evaluate model.
```
### Distribute Training
...
...
model_zoo/official/cv/vgg16/eval.py
浏览文件 @
4e3fa200
...
...
@@ -52,15 +52,15 @@ class ParameterReduce(nn.Cell):
def
parse_args
(
cloud_args
=
None
):
"""parse_args"""
parser
=
argparse
.
ArgumentParser
(
'mindspore classification test'
)
parser
.
add_argument
(
'--device_target'
,
type
=
str
,
default
=
'
GPU
'
,
choices
=
[
'Ascend'
,
'GPU'
],
parser
.
add_argument
(
'--device_target'
,
type
=
str
,
default
=
'
Ascend
'
,
choices
=
[
'Ascend'
,
'GPU'
],
help
=
'device where the code will be implemented. (Default: Ascend)'
)
# dataset related
parser
.
add_argument
(
'--dataset'
,
type
=
str
,
choices
=
[
"cifar10"
,
"imagenet2012"
],
default
=
"
imagenet2012
"
)
parser
.
add_argument
(
'--dataset'
,
type
=
str
,
choices
=
[
"cifar10"
,
"imagenet2012"
],
default
=
"
cifar10
"
)
parser
.
add_argument
(
'--data_path'
,
type
=
str
,
default
=
''
,
help
=
'eval data dir'
)
parser
.
add_argument
(
'--per_batch_size'
,
default
=
32
,
type
=
int
,
help
=
'batch size for per npu'
)
# network related
parser
.
add_argument
(
'--graph_ckpt'
,
type
=
int
,
default
=
1
,
help
=
'graph ckpt or feed ckpt'
)
parser
.
add_argument
(
'--pretrained'
,
default
=
''
,
type
=
str
,
help
=
'fully path of pretrained model to load. '
parser
.
add_argument
(
'--pre
_
trained'
,
default
=
''
,
type
=
str
,
help
=
'fully path of pretrained model to load. '
'If it is a direction, it will test all ckpt'
)
# logging related
...
...
@@ -68,9 +68,6 @@ def parse_args(cloud_args=None):
parser
.
add_argument
(
'--rank'
,
type
=
int
,
default
=
0
,
help
=
'local rank of distributed'
)
parser
.
add_argument
(
'--group_size'
,
type
=
int
,
default
=
1
,
help
=
'world size of distributed'
)
# roma obs
parser
.
add_argument
(
'--train_url'
,
type
=
str
,
default
=
""
,
help
=
'train url'
)
args_opt
=
parser
.
parse_args
()
args_opt
=
merge_args
(
args_opt
,
cloud_args
)
...
...
@@ -82,6 +79,8 @@ def parse_args(cloud_args=None):
args_opt
.
image_size
=
cfg
.
image_size
args_opt
.
num_classes
=
cfg
.
num_classes
args_opt
.
per_batch_size
=
cfg
.
batch_size
args_opt
.
momentum
=
cfg
.
momentum
args_opt
.
weight_decay
=
cfg
.
weight_decay
args_opt
.
buffer_size
=
cfg
.
buffer_size
args_opt
.
pad_mode
=
cfg
.
pad_mode
args_opt
.
padding
=
cfg
.
padding
...
...
@@ -130,23 +129,23 @@ def test(cloud_args=None):
args
.
logger
.
save_args
(
args
)
if
args
.
dataset
==
"cifar10"
:
net
=
vgg16
(
num_classes
=
args
.
num_classes
)
opt
=
Momentum
(
filter
(
lambda
x
:
x
.
requires_grad
,
net
.
get_parameters
()),
0.01
,
cfg
.
momentum
,
net
=
vgg16
(
num_classes
=
args
.
num_classes
,
args
=
args
)
opt
=
Momentum
(
filter
(
lambda
x
:
x
.
requires_grad
,
net
.
get_parameters
()),
0.01
,
args
.
momentum
,
weight_decay
=
args
.
weight_decay
)
loss
=
nn
.
SoftmaxCrossEntropyWithLogits
(
sparse
=
True
,
reduction
=
'mean'
,
is_grad
=
False
)
model
=
Model
(
net
,
loss_fn
=
loss
,
optimizer
=
opt
,
metrics
=
{
'acc'
})
param_dict
=
load_checkpoint
(
args
.
checkpoint_path
)
param_dict
=
load_checkpoint
(
args
.
pre_trained
)
load_param_into_net
(
net
,
param_dict
)
net
.
set_train
(
False
)
dataset
=
vgg_create_dataset
(
args
.
data_path
,
1
,
False
)
dataset
=
vgg_create_dataset
(
args
.
data_path
,
args
.
image_size
,
args
.
per_batch_size
,
training
=
False
)
res
=
model
.
eval
(
dataset
)
print
(
"result: "
,
res
)
else
:
# network
args
.
logger
.
important_info
(
'start create network'
)
if
os
.
path
.
isdir
(
args
.
pretrained
):
models
=
list
(
glob
.
glob
(
os
.
path
.
join
(
args
.
pretrained
,
'*.ckpt'
)))
if
os
.
path
.
isdir
(
args
.
pre
_
trained
):
models
=
list
(
glob
.
glob
(
os
.
path
.
join
(
args
.
pre
_
trained
,
'*.ckpt'
)))
print
(
models
)
if
args
.
graph_ckpt
:
f
=
lambda
x
:
-
1
*
int
(
os
.
path
.
splitext
(
os
.
path
.
split
(
x
)[
-
1
])[
0
].
split
(
'-'
)[
-
1
].
split
(
'_'
)[
0
])
...
...
@@ -154,14 +153,10 @@ def test(cloud_args=None):
f
=
lambda
x
:
-
1
*
int
(
os
.
path
.
splitext
(
os
.
path
.
split
(
x
)[
-
1
])[
0
].
split
(
'_'
)[
-
1
])
args
.
models
=
sorted
(
models
,
key
=
f
)
else
:
args
.
models
=
[
args
.
pretrained
,]
args
.
models
=
[
args
.
pre
_
trained
,]
for
model
in
args
.
models
:
if
args
.
dataset
==
"cifar10"
:
dataset
=
vgg_create_dataset
(
args
.
data_path
,
args
.
image_size
,
args
.
per_batch_size
,
training
=
False
)
else
:
dataset
=
classification_dataset
(
args
.
data_path
,
args
.
image_size
,
args
.
per_batch_size
)
dataset
=
classification_dataset
(
args
.
data_path
,
args
.
image_size
,
args
.
per_batch_size
)
eval_dataloader
=
dataset
.
create_tuple_iterator
()
network
=
vgg16
(
args
.
num_classes
,
args
,
phase
=
"test"
)
...
...
model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh
浏览文件 @
4e3fa200
...
...
@@ -47,6 +47,6 @@ do
cd
./train_parallel
$i
||
exit
echo
"start training for rank
$RANK_ID
, device
$DEVICE_ID
"
env
>
env.log
python train.py
--data_path
=
$2
--device_id
=
$i
&> log &
python train.py
--data_path
=
$2
--device_
target
=
"Ascend"
--device_
id
=
$i
&> log &
cd
..
done
\ No newline at end of file
model_zoo/official/cv/vgg16/src/vgg.py
浏览文件 @
4e3fa200
...
...
@@ -138,5 +138,5 @@ def vgg16(num_classes=1000, args=None, phase="train"):
>>> vgg16(num_classes=1000)
"""
net
=
Vgg
(
cfg
[
'16'
],
num_classes
=
num_classes
,
args
=
args
,
batch_norm
=
True
,
phase
=
phase
)
net
=
Vgg
(
cfg
[
'16'
],
num_classes
=
num_classes
,
args
=
args
,
batch_norm
=
args
.
batch_norm
,
phase
=
phase
)
return
net
model_zoo/official/cv/vgg16/train.py
浏览文件 @
4e3fa200
...
...
@@ -109,7 +109,7 @@ class ProgressMonitor(Callback):
def
parse_args
(
cloud_args
=
None
):
"""parameters"""
parser
=
argparse
.
ArgumentParser
(
'mindspore classification training'
)
parser
.
add_argument
(
'--device_target'
,
type
=
str
,
default
=
'
GPU
'
,
choices
=
[
'Ascend'
,
'GPU'
],
parser
.
add_argument
(
'--device_target'
,
type
=
str
,
default
=
'
Ascend
'
,
choices
=
[
'Ascend'
,
'GPU'
],
help
=
'device where the code will be implemented. (Default: Ascend)'
)
parser
.
add_argument
(
'--device_id'
,
type
=
int
,
default
=
1
,
help
=
'device id of GPU or Ascend. (Default: None)'
)
...
...
@@ -127,7 +127,7 @@ def parse_args(cloud_args=None):
# logging and checkpoint related
parser
.
add_argument
(
'--log_interval'
,
type
=
int
,
default
=
100
,
help
=
'logging interval'
)
parser
.
add_argument
(
'--ckpt_path'
,
type
=
str
,
default
=
'outputs/'
,
help
=
'checkpoint save location'
)
parser
.
add_argument
(
'--ckpt_interval'
,
type
=
int
,
default
=
5000
,
help
=
'ckpt_interval'
)
parser
.
add_argument
(
'--ckpt_interval'
,
type
=
int
,
default
=
2
,
help
=
'ckpt_interval'
)
parser
.
add_argument
(
'--is_save_on_master'
,
type
=
int
,
default
=
1
,
help
=
'save ckpt on master or all rank'
)
# distributed related
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录