I want to perform a convolution on a batch of images with respective weight from a batch of weight filters for example:
images = torch.ones(8, 32, 160, 608) #dimensions are B,C,H,W#
weights = torch.randn(8, 1, 32, 32) #dimensions are B,C,H,W#
for i in range(images.shape):
out.append( torch.nn.conv2d(images[i] , weights[i]) ) #I want to use a single filter for all the 32 channels of input image to get an output like (1,1,,)#
out = torch.stack(out)
#required output dimension should be like out.shape = (8,1,,)
weight shape is using
[out_channels=8, in_channels=1, height=32, width=32] which would create 8 output channels (activation maps) for an input with a single channel.
Your current input has 32 channels so I’m unsure how these weights should be applied.
Would you like to create a separate conv kernel for each sample in the input batch and each channel?
I have a batch size of 8 for input as well as weights (dim=0). So for each batch I want to use the respective weight of size (1,1,32,32) and convolve it with the respective input image of size (1,32,160,608). And for performing colvoution I want to use the single channel weight to be convolved with all the 32 channels of the input image and then sum all the resultants into a single channel output.