import torch.nn.functional as F
import torch
inputs = torch.arange(1, 21).reshape(1, 2, 2, 5)
filters = torch.arange(1, 7).reshape(2, 1, 1, 3)
print(inputs)
print(filters)
res = F.conv2d(input=inputs, weight=filters, stride=(1, 1), groups=2)
print(res)
输出
这说明输入的input为[1,2,2,5],kernel为[2,1,1,3],那么groups=2,此时kernel的第一个shape参数必须为groups的倍数,否则报错。这说明实际上是把input 变为group个[b,c/group,h,w]分别与kernel[cout/group,c/group,k1,k2]进行卷积后这group个结果进行concat的到最后【b,cout,h,w】的输出