我发现了一个使用groups
参数进行深度可分离卷积的PyTorch示例:链接:
class depthwise_separable_conv(nn.Module):
def __init__(self, nin, nout):
super(depthwise_separable_conv, self).__init__()
self.depthwise = nn.Conv2d(nin, nin, kernel_size=3, padding=1, groups=nin)
self.pointwise = nn.Conv2d(nin, nout, kernel_size=1)
def forward(self, x):
out = self.depthwise(x)
out = self.pointwise(out)
return out
我以前没有看过CNN中使用组的情况。就此而言,文档也有些简略:
“groups”控制输入和输出之间的连接。 “in_channels”和“out_channels”必须都能被组整除。
所以我的问题是:
1. CNN中的“groups”是什么? 2. 在哪些情况下需要使用“groups”?
(我猜这更多是一般性问题,而非特定于PyTorch。)