cleanUrl: "what-is-depthwise-convolution"
description: "Depthwise convolution을 쉽게 설명합니다."
PyTorch를 예로 들자면, nn.Conv1d
의 groups
파라미터가 아래 조건을 만족하면 이러한 convolution 연산을 depthwise convolution이라 한다.
groups == in_channels
groups == out_channels * K
(K는 양의 정수)‘Depthwise’라는 용어 때문에 바로 이해가 되지는 않는다. ‘Channelwise’ convolution 이었다면 이해가 더 쉽지는 않았을까?
nn.Conv1d
를 만져보면서 이해해보자.x = torch.randn([1, 4, 10])
groups=1
) 1D-convolution 연산을 수행하려면 아래와 같이 연산을 만들면 된다. (out_channels=4, kernel_size=3
이라고 하자)conv = nn.Conv1d(4, 4, 3)
conv(x).shape # (1, 4, 8)
Weight를 찍어보면 어떻게 생겼을까?
kernel_size
)인 filter가 4개(out_channels
) 있어야 하니까, (4, 4, 3)일 것.conv.weight.shape # (4, 4, 3)
groups = in_channels = 4
, groups = out_channels * 1
이므로 depthwise conv다.d_conv = nn.Conv1d(4, 4, 3, groups=4)
d_conv(x).shape # (1, 4, 8)
conv.weight.shape # (4, 1, 3)