mxnet DepthwiseConv2D

 

在 https://blog.csdn.net/zhqh100/article/details/90376732 中介绍MobileNet时,提到 DepthwiseConv2D,这是keras中的API,那mxnet中该 API 叫什么名字呢?

我跟踪了一下代码,以及打印summary之类的,基本搞清楚了,mxnet 中无论是 DepthwiseConv2D 还是 Conv2D,统一都叫做 Conv2D,参考如下调用代码(/home/luke/miniconda3/lib/python3.6/site-packages/gluoncv/model_zoo/mobilenet.py):

# pylint: disable= too-many-arguments
def _add_DepthwiseConv2D(out, channels=1, kernel=1, stride=1, pad=0,
              num_group=1, active=True, relu6=False, norm_layer=BatchNorm, norm_kwargs=None):
    out.add(nn.Conv2D(channels, kernel, stride, pad, groups=num_group, use_bias=False))
    print("kernel = %d, groups = %d, channels = %d" % (kernel, num_group, channels))
    out.add(norm_layer(scale=True, **({} if norm_kwargs is None else norm_kwargs)))
    if active:
        out.add(RELU6() if relu6 else nn.Activation('relu'))


区别在于其中的 groups 参数,http://mxnet.incubator.apache.org/api/python/gluon/nn.html

groups (int) – Controls the connections between inputs and outputs. At groups=1, all inputs are convolved to all outputs. At groups=2, the operation becomes equivalent to having two conv layers side by side, each seeing half the input channels, and producing half the output channels, and both subsequently concatenated.
而这里在调用时,如果需要分离卷积的话,channels值和groups值相等就可以了

            _add_DepthwiseConv2D(self.out,
                      in_channels * t,
                      kernel=3,
                      stride=stride,
                      pad=1,
                      num_group=in_channels * t,
                      relu6=True,
                      norm_layer=BatchNorm, norm_kwargs=None)


值都为 in_channels * t。
————————————————
版权声明:本文为CSDN博主「zhqh100」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhqh100/article/details/93894471

上一篇:MATLAB(矩阵基本运算)


下一篇:四旋翼无人机飞控系统设计(姿态解算)