Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
2d433e64
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看板
提交
2d433e64
编写于
5月 29, 2020
作者:
U
unknown
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
91adbf7e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
37 deletion
+23
-37
model_zoo/deeplabv3/evaluation.py
model_zoo/deeplabv3/evaluation.py
+10
-18
model_zoo/deeplabv3/train.py
model_zoo/deeplabv3/train.py
+13
-19
未找到文件。
model_zoo/deeplabv3/evaluation.py
浏览文件 @
2d433e64
#!/bin/bash
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -14,21 +13,13 @@
# limitations under the License.
# ============================================================================
"""evaluation."""
import
os
,
time
import
argparse
from
mindspore
import
context
from
mindspore
import
log
as
logger
from
mindspore.communication.management
import
init
import
mindspore.nn
as
nn
from
mindspore.nn.optim.momentum
import
Momentum
from
mindspore.train.loss_scale_manager
import
FixedLossScaleManager
from
mindspore
import
Model
,
ParallelMode
import
argparse
from
mindspore
import
Model
from
mindspore.train.serialization
import
load_checkpoint
,
load_param_into_net
from
mindspore.train.callback
import
Callback
,
CheckpointConfig
,
ModelCheckpoint
,
TimeMonitor
from
src.md_dataset
import
create_dataset
from
src.losses
import
OhemLoss
from
src.miou_precision
import
MiouPrecision
from
src.miou_precision
import
MiouPrecision
from
src.deeplabv3
import
deeplabv3_resnet50
from
src.config
import
config
parser
=
argparse
.
ArgumentParser
(
description
=
"Deeplabv3 evaluation"
)
...
...
@@ -44,15 +35,16 @@ print(args_opt)
if
__name__
==
"__main__"
:
args_opt
.
crop_size
=
config
.
crop_size
args_opt
.
base_size
=
config
.
crop_size
eval_dataset
=
create_dataset
(
args_opt
,
args_opt
.
data_url
,
args_opt
.
epoch_size
,
args_opt
.
batch_size
,
usage
=
"eval"
)
net
=
deeplabv3_resnet50
(
config
.
seg_num_classes
,
[
args_opt
.
batch_size
,
3
,
args_opt
.
crop_size
,
args_opt
.
crop_size
],
infer_scale_sizes
=
config
.
eval_scales
,
atrous_rates
=
config
.
atrous_rates
,
decoder_output_stride
=
config
.
decoder_output_stride
,
output_stride
=
config
.
output_stride
,
fine_tune_batch_norm
=
config
.
fine_tune_batch_norm
,
image_pyramid
=
config
.
image_pyramid
)
eval_dataset
=
create_dataset
(
args_opt
,
args_opt
.
data_url
,
args_opt
.
epoch_size
,
args_opt
.
batch_size
,
usage
=
"eval"
)
net
=
deeplabv3_resnet50
(
config
.
seg_num_classes
,
[
args_opt
.
batch_size
,
3
,
args_opt
.
crop_size
,
args_opt
.
crop_size
],
infer_scale_sizes
=
config
.
eval_scales
,
atrous_rates
=
config
.
atrous_rates
,
decoder_output_stride
=
config
.
decoder_output_stride
,
output_stride
=
config
.
output_stride
,
fine_tune_batch_norm
=
config
.
fine_tune_batch_norm
,
image_pyramid
=
config
.
image_pyramid
)
param_dict
=
load_checkpoint
(
args_opt
.
checkpoint_url
)
load_param_into_net
(
net
,
param_dict
)
mIou
=
MiouPrecision
(
config
.
seg_num_classes
)
metrics
=
{
'mIou'
:
mIou
}
metrics
=
{
'mIou'
:
mIou
}
loss
=
OhemLoss
(
config
.
seg_num_classes
,
config
.
ignore_label
)
model
=
Model
(
net
,
loss
,
metrics
=
metrics
)
model
.
eval
(
eval_dataset
)
\ No newline at end of file
model
.
eval
(
eval_dataset
)
\ No newline at end of file
model_zoo/deeplabv3/train.py
浏览文件 @
2d433e64
#!/bin/bash
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -14,18 +13,13 @@
# limitations under the License.
# ============================================================================
"""train."""
import
os
,
time
import
argparse
from
mindspore
import
context
from
mindspore
import
log
as
logger
from
mindspore.communication.management
import
init
import
mindspore.nn
as
nn
from
mindspore.nn.optim.momentum
import
Momentum
from
mindspore.train.loss_scale_manager
import
FixedLossScaleManager
from
mindspore
import
Model
,
ParallelMode
import
argparse
from
mindspore.train.serialization
import
load_checkpoint
,
load_param_into_net
from
mindspore.train.callback
import
Callback
,
CheckpointConfig
,
ModelCheckpoint
,
TimeMonitor
from
mindspore.train.callback
import
Callback
,
CheckpointConfig
,
ModelCheckpoint
,
TimeMonitor
from
src.md_dataset
import
create_dataset
from
src.losses
import
OhemLoss
from
src.deeplabv3
import
deeplabv3_resnet50
...
...
@@ -40,8 +34,7 @@ parser.add_argument("--device_id", type=int, default=0, help="Device id, default
parser
.
add_argument
(
'--checkpoint_url'
,
default
=
None
,
help
=
'Checkpoint path'
)
parser
.
add_argument
(
"--enable_save_ckpt"
,
type
=
str
,
default
=
"true"
,
help
=
"Enable save checkpoint, default is true."
)
parser
.
add_argument
(
'--max_checkpoint_num'
,
type
=
int
,
default
=
5
,
help
=
'Max checkpoint number.'
)
parser
.
add_argument
(
"--save_checkpoint_steps"
,
type
=
int
,
default
=
1000
,
help
=
"Save checkpoint steps, "
"default is 1000."
)
parser
.
add_argument
(
"--save_checkpoint_steps"
,
type
=
int
,
default
=
1000
,
help
=
"Save checkpoint steps, default is 1000."
)
parser
.
add_argument
(
"--save_checkpoint_num"
,
type
=
int
,
default
=
1
,
help
=
"Save checkpoint numbers, default is 1."
)
args_opt
=
parser
.
parse_args
()
print
(
args_opt
)
...
...
@@ -63,22 +56,22 @@ class LossCallBack(Callback):
cb_params
=
run_context
.
original_args
()
print
(
"epoch: {}, step: {}, outputs are {}"
.
format
(
cb_params
.
cur_epoch_num
,
cb_params
.
cur_step_num
,
str
(
cb_params
.
net_outputs
)))
def
model_fine_tune
(
flags
,
net
,
fix_weight_layer
):
def
model_fine_tune
(
flags
,
train_
net
,
fix_weight_layer
):
checkpoint_path
=
flags
.
checkpoint_url
if
checkpoint_path
is
None
:
return
param_dict
=
load_checkpoint
(
checkpoint_path
)
load_param_into_net
(
net
,
param_dict
)
for
para
in
net
.
trainable_params
():
load_param_into_net
(
train_
net
,
param_dict
)
for
para
in
train_
net
.
trainable_params
():
if
fix_weight_layer
in
para
.
name
:
para
.
requires_grad
=
False
para
.
requires_grad
=
False
if
__name__
==
"__main__"
:
if
args_opt
.
distribute
==
"true"
:
context
.
set_auto_parallel_context
(
parallel_mode
=
ParallelMode
.
DATA_PARALLEL
,
mirror_mean
=
True
)
init
()
args_opt
.
base_size
=
config
.
crop_size
args_opt
.
crop_size
=
config
.
crop_size
train_dataset
=
create_dataset
(
args_opt
,
args_opt
.
data_url
,
args_opt
.
epoch_size
,
args_opt
.
batch_size
,
usage
=
"train"
)
train_dataset
=
create_dataset
(
args_opt
,
args_opt
.
data_url
,
args_opt
.
epoch_size
,
args_opt
.
batch_size
,
usage
=
"train"
)
dataset_size
=
train_dataset
.
get_dataset_size
()
time_cb
=
TimeMonitor
(
data_size
=
dataset_size
)
callback
=
[
time_cb
,
LossCallBack
()]
...
...
@@ -87,13 +80,14 @@ if __name__ == "__main__":
keep_checkpoint_max
=
args_opt
.
save_checkpoint_num
)
ckpoint_cb
=
ModelCheckpoint
(
prefix
=
'checkpoint_deeplabv3'
,
config
=
config_ck
)
callback
.
append
(
ckpoint_cb
)
net
=
deeplabv3_resnet50
(
config
.
seg_num_classes
,
[
args_opt
.
batch_size
,
3
,
args_opt
.
crop_size
,
args_opt
.
crop_size
],
infer_scale_sizes
=
config
.
eval_scales
,
atrous_rates
=
config
.
atrous_rates
,
decoder_output_stride
=
config
.
decoder_output_stride
,
output_stride
=
config
.
output_stride
,
fine_tune_batch_norm
=
config
.
fine_tune_batch_norm
,
image_pyramid
=
config
.
image_pyramid
)
net
=
deeplabv3_resnet50
(
config
.
seg_num_classes
,
[
args_opt
.
batch_size
,
3
,
args_opt
.
crop_size
,
args_opt
.
crop_size
],
infer_scale_sizes
=
config
.
eval_scales
,
atrous_rates
=
config
.
atrous_rates
,
decoder_output_stride
=
config
.
decoder_output_stride
,
output_stride
=
config
.
output_stride
,
fine_tune_batch_norm
=
config
.
fine_tune_batch_norm
,
image_pyramid
=
config
.
image_pyramid
)
net
.
set_train
()
model_fine_tune
(
args_opt
,
net
,
'layer'
)
loss
=
OhemLoss
(
config
.
seg_num_classes
,
config
.
ignore_label
)
opt
=
Momentum
(
filter
(
lambda
x
:
'beta'
not
in
x
.
name
and
'gamma'
not
in
x
.
name
and
'depth'
not
in
x
.
name
and
'bias'
not
in
x
.
name
,
net
.
trainable_params
()),
learning_rate
=
config
.
learning_rate
,
momentum
=
config
.
momentum
,
weight_decay
=
config
.
weight_decay
)
model
=
Model
(
net
,
loss
,
opt
)
model
.
train
(
args_opt
.
epoch_size
,
train_dataset
,
callback
)
\ No newline at end of file
model
.
train
(
args_opt
.
epoch_size
,
train_dataset
,
callback
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录