Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
2065383e
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看板
提交
2065383e
编写于
5月 29, 2020
作者:
Y
yangyongjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pylint fix
上级
ee2efd35
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
51 deletion
+54
-51
model_zoo/deeplabv3/evaluation.py
model_zoo/deeplabv3/evaluation.py
+8
-5
model_zoo/deeplabv3/src/backbone/resnet_deeplab.py
model_zoo/deeplabv3/src/backbone/resnet_deeplab.py
+46
-46
未找到文件。
model_zoo/deeplabv3/evaluation.py
浏览文件 @
2065383e
...
...
@@ -22,6 +22,8 @@ from src.losses import OhemLoss
from
src.miou_precision
import
MiouPrecision
from
src.deeplabv3
import
deeplabv3_resnet50
from
src.config
import
config
parser
=
argparse
.
ArgumentParser
(
description
=
"Deeplabv3 evaluation"
)
parser
.
add_argument
(
'--epoch_size'
,
type
=
int
,
default
=
2
,
help
=
'Epoch size.'
)
parser
.
add_argument
(
"--device_id"
,
type
=
int
,
default
=
0
,
help
=
"Device id, default is 0."
)
...
...
@@ -32,14 +34,16 @@ parser.add_argument('--checkpoint_url', default=None, help='Checkpoint path')
args_opt
=
parser
.
parse_args
()
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
,
device_id
=
args_opt
.
device_id
)
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
)
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
)
...
...
@@ -47,4 +51,3 @@ if __name__ == "__main__":
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_zoo/deeplabv3/src/backbone/resnet_deeplab.py
浏览文件 @
2065383e
...
...
@@ -93,31 +93,30 @@ def _stob_deep_conv_btos_bn_relu(in_channel,
def
_stob_conv_btos_bn_relu
(
in_channel
,
out_channel
,
ksize
,
space_to_batch_block_shape
,
batch_to_space_block_shape
,
paddings
,
crops
,
stride
=
1
,
padding
=
0
,
dilation
=
1
,
pad_mode
=
"pad"
,
use_batch_statistics
=
False
):
out_channel
,
ksize
,
space_to_batch_block_shape
,
batch_to_space_block_shape
,
paddings
,
crops
,
stride
=
1
,
padding
=
0
,
dilation
=
1
,
pad_mode
=
"pad"
,
use_batch_statistics
=
False
):
"""Get a spacetobatch -> conv2d -> batchnorm -> relu -> batchtospace layer"""
return
nn
.
SequentialCell
(
[
SpaceToBatch
(
space_to_batch_block_shape
,
paddings
),
nn
.
Conv2d
(
in_channel
,
out_channel
,
kernel_size
=
ksize
,
stride
=
stride
,
padding
=
padding
,
dilation
=
dilation
,
pad_mode
=
pad_mode
),
BatchToSpace
(
batch_to_space_block_shape
,
crops
),
nn
.
BatchNorm2d
(
out_channel
,
use_batch_statistics
=
use_batch_statistics
),
nn
.
ReLU
()]
)
return
nn
.
SequentialCell
([
SpaceToBatch
(
space_to_batch_block_shape
,
paddings
),
nn
.
Conv2d
(
in_channel
,
out_channel
,
kernel_size
=
ksize
,
stride
=
stride
,
padding
=
padding
,
dilation
=
dilation
,
pad_mode
=
pad_mode
),
BatchToSpace
(
batch_to_space_block_shape
,
crops
),
nn
.
BatchNorm2d
(
out_channel
,
use_batch_statistics
=
use_batch_statistics
),
nn
.
ReLU
()]
)
def
_make_layer
(
block
,
...
...
@@ -206,6 +205,7 @@ class BatchToSpace(nn.Cell):
class
_DepthwiseConv2dNative
(
nn
.
Cell
):
"""Depthwise Conv2D Cell."""
def
__init__
(
self
,
in_channels
,
channel_multiplier
,
...
...
@@ -242,6 +242,7 @@ class _DepthwiseConv2dNative(nn.Cell):
class
DepthwiseConv2dNative
(
_DepthwiseConv2dNative
):
"""Depthwise Conv2D Cell."""
def
__init__
(
self
,
in_channels
,
channel_multiplier
,
...
...
@@ -315,31 +316,31 @@ class BottleneckV1(nn.Cell):
padding
=
1
,
dilation
=
1
,
use_batch_statistics
=
use_batch_statistics
)
if
use_batch_to_stob_and_btos
==
True
:
if
use_batch_to_stob_and_btos
:
self
.
conv_bn2
=
_stob_conv_btos_bn_relu
(
mid_channels
,
mid_channels
,
ksize
=
3
,
stride
=
stride
,
padding
=
0
,
dilation
=
1
,
space_to_batch_block_shape
=
2
,
batch_to_space_block_shape
=
2
,
paddings
=
[[
2
,
3
],
[
2
,
3
]],
crops
=
[[
0
,
1
],
[
0
,
1
]],
space_to_batch_block_shape
=
2
,
batch_to_space_block_shape
=
2
,
paddings
=
[[
2
,
3
],
[
2
,
3
]],
crops
=
[[
0
,
1
],
[
0
,
1
]],
pad_mode
=
"valid"
,
use_batch_statistics
=
use_batch_statistics
)
self
.
conv3
=
nn
.
Conv2d
(
mid_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
1
)
self
.
bn3
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
self
.
bn3
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
if
in_channels
!=
out_channels
:
conv
=
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
stride
)
bn
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
bn
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
self
.
downsample
=
nn
.
SequentialCell
([
conv
,
bn
])
else
:
self
.
downsample
=
Subsample
(
stride
)
...
...
@@ -397,23 +398,23 @@ class BottleneckV2(nn.Cell):
stride
=
stride
,
padding
=
0
,
dilation
=
1
,
space_to_batch_block_shape
=
2
,
batch_to_space_block_shape
=
2
,
paddings
=
[[
2
,
3
],
[
2
,
3
]],
crops
=
[[
0
,
1
],
[
0
,
1
]],
space_to_batch_block_shape
=
2
,
batch_to_space_block_shape
=
2
,
paddings
=
[[
2
,
3
],
[
2
,
3
]],
crops
=
[[
0
,
1
],
[
0
,
1
]],
pad_mode
=
"valid"
,
use_batch_statistics
=
use_batch_statistics
)
self
.
conv3
=
nn
.
Conv2d
(
mid_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
1
)
self
.
bn3
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
self
.
bn3
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
if
in_channels
!=
out_channels
:
conv
=
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
stride
)
bn
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
bn
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
self
.
downsample
=
nn
.
SequentialCell
([
conv
,
bn
])
else
:
self
.
downsample
=
Subsample
(
stride
)
...
...
@@ -465,14 +466,14 @@ class BottleneckV3(nn.Cell):
out_channels
,
kernel_size
=
1
,
stride
=
1
)
self
.
bn3
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
self
.
bn3
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
if
in_channels
!=
out_channels
:
conv
=
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
stride
)
bn
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
bn
=
nn
.
BatchNorm2d
(
out_channels
,
use_batch_statistics
=
use_batch_statistics
)
self
.
downsample
=
nn
.
SequentialCell
([
conv
,
bn
])
else
:
self
.
downsample
=
Subsample
(
stride
)
...
...
@@ -502,9 +503,8 @@ class ResNetV1(nn.Cell):
super
(
ResNetV1
,
self
).
__init__
()
self
.
layer_root
=
nn
.
SequentialCell
(
[
RootBlockBeta
(
fine_tune_batch_norm
),
nn
.
MaxPool2d
(
kernel_size
=
(
3
,
3
),
stride
=
(
2
,
2
),
#padding=1,
nn
.
MaxPool2d
(
kernel_size
=
(
3
,
3
),
stride
=
(
2
,
2
),
pad_mode
=
'same'
)])
self
.
layer1_1
=
BottleneckV1
(
128
,
256
,
stride
=
1
,
use_batch_statistics
=
fine_tune_batch_norm
)
self
.
layer1_2
=
BottleneckV2
(
256
,
256
,
stride
=
1
,
use_batch_statistics
=
fine_tune_batch_norm
)
...
...
@@ -519,7 +519,7 @@ class ResNetV1(nn.Cell):
self
.
layer3_4
=
BottleneckV2
(
1024
,
1024
,
stride
=
1
,
use_batch_statistics
=
fine_tune_batch_norm
)
self
.
layer3_5
=
BottleneckV2
(
1024
,
1024
,
stride
=
1
,
use_batch_statistics
=
fine_tune_batch_norm
)
self
.
layer3_6
=
BottleneckV2
(
1024
,
1024
,
stride
=
1
,
use_batch_statistics
=
fine_tune_batch_norm
)
self
.
layer4_1
=
BottleneckV1
(
1024
,
2048
,
stride
=
1
,
use_batch_to_stob_and_btos
=
True
,
use_batch_statistics
=
fine_tune_batch_norm
)
self
.
layer4_2
=
BottleneckV2
(
2048
,
2048
,
stride
=
1
,
use_batch_to_stob_and_btos
=
True
,
...
...
@@ -542,7 +542,7 @@ class ResNetV1(nn.Cell):
x
=
self
.
layer3_4
(
x
)
x
=
self
.
layer3_5
(
x
)
x
=
self
.
layer3_6
(
x
)
x
=
self
.
layer4_1
(
x
)
x
=
self
.
layer4_2
(
x
)
c5
=
self
.
layer4_3
(
x
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录