'How to Customize the convolution operation?

I want to perform a customize convolution operation in tensorflow using a 2x2 filter. The operation is like if we have a filter having 2 channels [[[1,2],[3,4]],[[5,6],[7,8]]] and the image is like in 2 channels [[[1,2],[3,4]],[[5,6],[7,8]]] the output should be like output = [[26,40],[58,80]]. This is output because output[0][0] = 1 * 1 + 5 * 5, output[0][1]=2 * 2 + 5 * 5, output[1][0]=3 * 3 + 7 * 7, output[1][1]= 4 * 4 + 8 * 8. Basically what we are doing here is we are multiplying the weights of image and weights of channel in one row and column and then adding up something like 1x1 convolution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source