Skip to content

Latest commit

ย 

History

History
80 lines (64 loc) ยท 3.25 KB

File metadata and controls

80 lines (64 loc) ยท 3.25 KB

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications, Andrew G. Howard et al

paper

Summary

  • MobileNet์€ depthwise separable convolution์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋ฒผ์šด deep neural network
  • ์—ฐ์‚ฐ์ด ํšจ์œจ์ ์œผ๋กœ ์„ค๊ณ„๋œ MobileNet์„ ๋” ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก width multiplier ์™€ resolution multiplier ๋‘๊ฐ€์ง€ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋„์ž…

Depthwise separable Convolution

Depthwise Convolution : ๋ ˆ์ด์–ด์—์„œ filtering ํ•˜๋Š” ๋ถ€๋ถ„

  • HWC์˜ conv output์„ C๋‹จ์œ„๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ฐ๊ฐ conv filter๋ฅผ ์ ์šฉํ•˜์—ฌ output์„ ๋งŒ๋“ค๊ณ  ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ ํ•ฉ์น˜๋ฉด conv filter๊ฐ€ ํ›จ์”ฌ ๋” ์ ์€ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  ๋™์ผํ•œ ํฌ๊ธฐ์˜ output์„ ๋‚ผ ์ˆ˜ ์žˆ์Œ
  • ๊ฐ ํ•„ํ„ฐ์— ๋Œ€ํ•œ ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ ํ•„ํ„ฐ๋กœ๋ถ€ํ„ฐ ๋…๋ฆฝ์ ์ผ ํ•„์š”๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ์— ์žฅ์ 
class depthwise_conv(nn.Module):
  def __init__(self, nin, kernels_per_layer):
    super(depthwise_separable_conv, self).__init__()
    # groups = nin, ์ž…๋ ฅ ๋ ˆ์ด์–ด๋ฅผ nin ๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ group์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ํ•ด๋‹น ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๊ฒ ๋‹ค. (group์˜ default = 1)
    self.depthwise = nn.Conv2d(nin, nin*kernels_per_layer, kernel_size=3, padding= 1, groups = nin)
    
  def forward(self, x):
    out = self.depthwise(x)
    return out

Pointwise convolution: filter๋œ ๋ถ€๋ถ„์„ comvining ํ•˜๋Š” ๋ถ€๋ถ„

  • 1x1 Conv๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” filter, ์ฃผ๋กœ ๊ธฐ์กด์˜ matrix์˜ ๊ฒฐ๊ณผ๋ฅผ ๋…ผ๋ฆฌ์ ์œผ๋กœ ๋‹ค์‹œ shuffleํ•ด์„œ ๋ด…์•„๋‚ด๋Š” ๊ฒƒ์„ ๋ชฉ์ 
  • Channel์ˆ˜๋ฅผ ์ค„์ด๊ฑฐ๋‚˜ ๋Š˜๋ฆฌ๋Š” ๋ชฉ์ ์œผ๋กœ๋„ ๋งŽ์ด ์“ฐ์ž„
class pointwise_conv(nn.Module):
  def __init__(self, nin, nout):
        super(depthwise_separable_conv, self).__init__()
        self.pointwise = nn.Conv2d(nin, nout, kernel_size=1)

    def forward(self, x):
        out = self.pointwise(x)
        return out

Depthwise Separable Convolution

  • Depthwise convolution ํ›„ Pointwise convolution
    • 3x3 filter๋ฅผ ํ†ตํ•ด conv ์—ฐ์‚ฐ ์ง„ํ–‰, ์„œ๋กœ ๋‹ค๋ฅธ channel๋“ค์˜ ์ •๋ณด๋„ ๊ณต์œ ํ•˜๋ฉด์„œ ๋™์‹œ์— ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜๋„ ์ค„์ด๊ธฐ ๊ฐ€๋Šฅ
class depthwise_separable_conv(nn.Module):
    def __init__(self, nin, kernels_per_layer, nout):
        super(depthwise_separable_conv, self).__init__()
        self.depthwise = nn.Conv2d(nin, nin * kernels_per_layer, kernel_size=3, padding=1, groups=nin)
        self.pointwise = nn.Conv2d(nin * kernels_per_layer, nout, kernel_size=1)

    def forward(self, x):
        out = self.depthwise(x)
        out = self.pointwise(out)
        return out
class SeparableConv2d(nn.Module):
    def __init__(self, in_channels, out_channels, stride):
        super(SeparableConv2d, self).__init__()

        self.depthwise = nn.Sequential(
            nn.Conv2d(in_channels, in_channels, kernel_size=3, padding=1, stride=stride),
            nn.BatchNorm2d(in_channels),
            nn.ReLU(inplace=True),
        )
        self.pointwise = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1),
            nn.BatchNorm2d(out_channels),
            nn.ReLU(inplace=True)
        )

    def forward(self, x):
        x = self.depthwise(x)
        x = self.pointwise(x)
        return x