How to apply different kernels for each example in a batch

I’m implementing a dynamic convolution where the kernel is calculated from another network instead of directly learned, but the F.Conv2d function doesn’t seem to support a kernel of size [batch, in, out, H, W]. Is there a workaround for this? Thank you.

torch.nn.functional.conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1) → Tensor
filters = torch.randn(8,4,3,3)
inputs = torch.randn(1,4,5,5)
F.conv2d(inputs, filters, padding=1)

Sorry my question was confusing, I edited the question a bit. My question is how to do convolution using different filters for each batch.

1 Like