why do we need to flip kernel before using conv2 in CNN?
Afficher commentaires plus anciens
We know that function conv2 can prefom convolution (between image and kernel ) and flip kernel before apply convolution to image according to defnition of convolution
y = conv2(image, kernel, 'valid')
.However, in convolution neural network(CNN) ,they flip the kernel before the use conv2
kernel = rot90(kernel, 2);
y = conv2(image, kernel, 'valid');
which means the kernel flip twice and this correlation not convolution why
3 commentaires
Mohammedee
le 4 Juil 2022
Mohammedee
le 4 Juil 2022
Modifié(e) : Mohammedee
le 4 Juil 2022
Réponses (1)
The field of neural networks uses the term "convolution" loosely. There are other differences as well. We also know that in traditional DSP theory, convolution operations don't contain a stride parameter, but in the NN world, they do.
5 commentaires
Mohammedee
le 10 Juil 2022
Basically, neural networks researchers are not using the terminology "convolution" in the classical way. A true convolution in the original sense of the word should include a flip and should never have stride>1. That's the way convolution was originally defined. Without the flip, it should be called correlation, as you say.
Mohammedee
le 10 Juil 2022
Modifié(e) : Mohammedee
le 10 Juil 2022
Mohammedee
le 10 Juil 2022
Modifié(e) : Mohammedee
le 10 Juil 2022
If you use conv2(image, W), MATLAB will first "flip" W, reversing its rows and columns
Yes, conv2 will flip W internally and that is the correct thing for it to do, because that is the way convolution is defined. This definition ensures that conv2(1,W) = W. Example:
W=[1 2;3 4]
conv2(1,W)
If you were to flip W manually, prior to giving it to conv2, it would mess this up:
conv2(1,rot90(W,2))
Catégories
En savoir plus sur Get Started with Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!