Table of contents
Cross-correlation operation definition
Cross-correlation operation diagram
Complete calculation example of cross-correlation operation
Convolution Mathematical Definition
The difference between convolution and cross-correlation operations
Why can convolution in deep learning be replaced by cross-correlation operations
Cross-correlation operation definition
In the two-dimensional cross-correlation operation, the convolution window starts from the top left of the input array, and slides on the input array in order from left to right and top to bottom. When the convolution window slides to a certain position, the input sub-array in the window and the kernel array are multiplied and summed according to the corresponding elements to obtain the elements at the corresponding position in the output array.
Cross-correlation operation diagram
Suppose we have an image and a filter
We perform Cross-correlation (cross-correlation operation) on the blue area in the image
Then the calculation method at point E is:
G[3,3]=a∗A+b∗B+c∗C+d∗D+e∗E+f∗F+g∗G+h∗H+i∗I
Complete calculation example of cross-correlation operation
The input array is 3*3 , the kernel array is 2*2 , and the input array is calculated as follows:
Convolution Mathematical Definition
Convolution operation diagram
We still use the above cross-correlation calculation picture, we remember that the cycle order of cross-correlation is from left to right, from top to bottom .
The convolution is from right to left, from bottom to top , that is, the calculation at point E is: G[3,3]=a∗I+b∗H+c∗G+d∗F+e∗E+f ∗D+g∗C+h∗B+i∗A Then this is equivalent to flipping the 'filter' , that is, first flipping up and down, then flipping left and right, and then performing cross-correlation operations, as shown below:
But why do we do this, what's the point, let's take a look
The difference between convolution and cross-correlation operations
Consider, a picture is as follows, we perform cross-correlation, and the results are as follows:
If the above is replaced by a graph of real points
We see that the result obtained is like a filter, but flipped. Therefore, if we flip the filter once and then perform cross-correlation, then adding the above flip is two flips, and the obtained image will remain unchanged.
Then the convolution has the following properties
Identity: E=[...0,0,1,0,0...], F*E=F (you can think about cross-correlation)
So when are convolution and cross-correlation the same?
When the filter is symmetrical about the x-axis and the y-axis, the usual Average filter and the Gaussian filter are both, and both get the same results.
Why can convolution in deep learning be replaced by cross-correlation operations
In most deep learning tutorials now, convolution is defined as a point-wise multiplication of an image matrix and a convolution kernel . In fact, this kind of operation should also be cross-correlation, and convolution needs to rotate the convolution kernel 180 degrees clockwise (that is, flip the convolution kernel up and down and then flip it left and right) and then do some multiplication . Although convolution operations and cross-correlation operations are similar, if they use the same kernel array, the output is often not the same for the same input.
Then, you may be wondering why the convolutional layer can use cross-correlation operations instead of convolution operations in deep learning. The main reason for this is that the kernel array is learned in deep learning: no matter whether the convolution layer uses cross-correlation operations or convolution operations, it will not affect the output of the model prediction. Assume that the convolutional layer uses cross-correlation operations to learn a certain kernel array. Assuming other conditions remain unchanged, the kernel array learned by convolution operation is the cross-correlation kernel array flipped up and down and left and right. That is to say, when the original input is convolved with the learned flipped kernel array, the same output is still obtained. Therefore, most convolution operations mentioned in deep learning refer to cross-correlation operations.
If you have any questions about the article, or other questions about Python, you can leave a message in the comment area or private message me
If the content of the article is helpful to you, thank you for liking + following!
Follow GZH below: Axu Algorithm and Machine Learning, you can get more dry content ~ welcome to learn and exchange together