边缘检测模型结构
DexiNed 由密集极端初始网络(Dexi)和上采样块(UB)组成,其中上采样块是DexiNed 用于边缘细化的关键组件,来自 Dexi 块的每个输出都馈送到 UB。
DexiNed主要有6个块的编码器形成,可以参考Xception,蓝色块由两个卷积层形成,3×3卷积核——BN——ReLU,max-pooling为核大小是3×3,stride是2.整体构造遵循多尺度,对应会有上采样流程。
UB 由条件堆叠子块形成。 每一个子块有 2 层,一层是卷积层,另外一层是反卷积层;有两种类型的子块。
MindSpore实现:
"""DexiNed 网络结构"""
def weight_init(net):
for name, param in net.parameters_and_names():
if 'weight' in name:
param.set_data(
init.initializer(
init.XavierNormal(),
param.shape,
param.dtype))
if 'bias' in name:
param.set_data(init.initializer('zeros', param.shape, param.dtype))
class CoFusion(nn.Cell):
def __init__(self, in_ch, out_ch):
super().__init__()
self.conv1 = nn.Conv2d(
in_ch, 64, kernel_size=3,
stride=1, padding=1, has_bias=True,
pad_mode="pad", weight_init=init.XavierNormal())
self.conv2 = nn.Conv2d(
64, 64, kernel_size=3,
stride=1, padding=1, has_bias=True,
pad_mode="pad", weight_init=init.XavierNormal())
self.conv3 = nn.Conv2d(
64, out_ch, kernel_size=3,
stride=1, padding=1, has_bias=True,
pad_mode="pad", weight_init=init.XavierNormal())
self.relu = nn.ReLU()
self.norm_layer1 = nn.GroupNorm(4, 64)
self.norm_layer2 = nn.GroupNorm(4, 64)
def construct(self, x):
attn = self.relu(self.norm_layer1(self.conv1(x)))
attn = self.relu(self.norm_layer2(self.conv2(attn)))
attn = ops.softmax(self.conv3(attn), axis=1)
return ((x * attn).sum(1)).expand_dims(1)
class _DenseLayer(nn.Cell):
def __init__(self, input_features, out_features):
super(_DenseLayer, self).__init__()
self.conv1 = nn.Conv2d(
input_features, out_features, kernel_size=3,
stride=1, padding=2, pad_mode="pad", </