Convolution without summation?

Hi there,

Is there any way to perform a convolution but without summation? Concretely, assume we have a Bx3x5x5 input and a 3x3x3 kernel, when we do a conv2d operation, we get a Bx1x4x4 output. For each conv-ed kernel, the result (Bx3x3x3) is summed both over H,W dimension and C dimension and produces a Bx1x1x1 scalar, and performing this operation over all locations gives the final Bx1x4x4 output. Is there any way to get the intermediate Bx3x3x3 results for each conv-ed kernel? i.e. without performing the summation over H,W, and C dimension, and thus the final result has a size of Bx3x3x3x4x4.

I know there is a groups option in conv2d, and by setting groups=channel_in, we essentially prevent the summation over the C dimension, but how can we prevent the summation over the H and W dimension?

Thanks

(Edit: I wrote Unbind first, but it needs to be torch.nn.Unfold, thank you for pointing this out, I changed it here).

torch.nn.Unfold gets you the patches that you could feed into matrix multiplication to get the convolution result (after reshaping).
If you then use pointwise multiplication with broadcasting, you should roughly get what you want (albeit in a different shape).

The torch.nn.Unfold documentation has an example of how to mimic convolution with torch.nn.Unfold and matmul.

Best regards

Thomas

Hi Thomas,

Thanks for your reply. I took a look at the torch.nn.unbind documentation but didn’t see the example you mentioned. Could you paste a link to it?
Thanks.

Regards

Charlie

Oh, I’m sorry, I meant torch.nn.Unfold!