卷积神经网络数学原理
It took me soo much time to understand how CNN is working. And trust me, the content on this is incredibly low, like really low. Everywhere they will tell you how forward propagation works in CNN, but never even start on backward prorogation. And without understanding the full picture, one’s understanding always remains half-baked.
我花了很多时间来了解CNN的工作方式。 相信我,这方面的内容简直是低得令人难以置信。 他们到处都会告诉您前向传播在CNN中是如何工作的,但从来没有从后向授权开始。 在不了解全部情况的情况下,一个人的了解总是半生半熟。
先决条件 (Pre-requisites)
- Should be familiar with Basics of CNN — Convolution layer, Max Pooling, Fully Connected layer. Do a basic google search and understand these concepts. Should take an hour or so to get started. 应该熟悉CNN的基础知识-卷积层,最大池化,完全连接层。 做一个基本的谷歌搜索,并了解这些概念。 应该花一个小时左右的时间来开始。
- Differential calculus — Should know how chain rule works and basic rules of differentiation. 微分演算—应该知道链式规则的工作原理和微分的基本规则。
Should know how back propagation maths actually works in ANN. I would highly recommend reading my previous article on this, in case you aren’t aware.
应该知道反向传播数学实际上是如何在ANN中工作的。 如果您不知道,我强烈建议您阅读我以前的文章。
本文的性质 (Nature of this article)
So, my main problem with the rest of the articles was — nowhere they have mentioned the overall flow. Each layer and concepts were beautifully explained but how do backpropagation works across the layers — that info was missing. So, it was very difficult for me to visualize how the errors were flowing backward overall. So, this article will take a few scenarios of CNN and will try to make you understand the overall flow.
因此,我对其余文章的主要问题是-他们没有提到总体流程。 每层和每层的概念都得到了很好的解释,但是反向传播如何在各层中进行—信息丢失了。 因此,我很难想象错误是如何整体倒退的。 因此,本文将介绍CNN的一些情况,并尝试使您理解整体流程。
The intent is not to cover depth but the breadth and overall flow. For depth, I’ll point you to the relevant articles wherever needed to help you with a deeper intuition. Consider this article as an index for CNN maths. Just to set the expectations clearly, this won’t be a 5 min read. But, will ask you to read up relevant articles as and when required.
目的不是覆盖深度,而是覆盖范围和整体流程。 为了深入了解,我将在任何需要的地方为您提供相关文章,以帮助您更深入地了解。 考虑将本文作为CNN数学的索引。 只是为了清楚地设定期望,这不会是5分钟的阅读时间。 但是,请您在需要时阅读相关文章。
场景1:1个卷积层+ 1个全连接层 (Scenario 1: 1 Convolution Layer + 1 Fully Connected Layer)
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/26f214d8a88a462515d582ae08e7f892.png)
前进通行证(Forward Pass)
X is the input image, say (3*3 matrix) and Filter is a (2*2 matrix). Both will be convoluted to give output XX (2*2 matrix).
X是输入图像,例如(3 * 3矩阵),Filter是(2 * 2矩阵)。 两者都将被卷积以给出输出XX(2 * 2矩阵)。
Now, XX will be flattened and will be fed to a fully connected network with w (1*4 matrix) as weights, which will give an— Output.
现在,将XX展平并以w(1 * 4矩阵)作为权重将其馈送到完全连接的网络,这将给出-输出。
Finally, we will calculate Error in the end by calculating mean squared error between Y (expected) and Output (actual).
最后,我们将通过计算Y(预期)和Output(实际)之间的均方误差来最终计算Error。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/6b0e128c11d881ff96afeb197887d2a4.png)
I would highly advise you to calculate XX on your own. This will give you an intuition of Convolution layer.
我强烈建议您自己计算XX。 这将为您提供卷积层的直觉。
后退通行证 (Backward Pass)
The goal of the backward pass is to choose such values of Filter and w, so that we can decrease E. So, basically our goal is how should we change w and Filter, so that E can be decreased.
复路的目标是选择过滤器和W的这样的值,这样我们就可以减少即因此,基本上我们的目标是如何更改w和Filter,以便可以降低E。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/d1e105c0db684d134259de6c39ff9311.png)
Let’s start with the first term.
让我们从第一学期开始。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/d2da419bc0ce680e08ad1457048ff7a3.png)
Guess how?!
猜怎么着?!
Line 1: Using chain rule.Line 2: Using differential calculus. Spend a minute on this. Should be easily understandable. If not check my previous article (mentioned in the pre-requisite). Or check this one.
第1行:使用链式规则。第2行:使用微积分。 花一点时间。 应该很容易理解。 如果没有,请查看我的上一篇文章(前提条件中提到)。 或检查这一个。
Before moving forward, do make sure you do these calculations on your own. Please comment in case this is not easily understandable.
在继续之前,请确保您自己进行这些计算。 如果这不容易理解,请发表评论。
Moving to the second term.
移至第二学期。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/cfb23ae18b75113a5b5e92243c3e53a1.png)
Ooo.. too much of weird logic here? Stick with me, will help you understand this.
噢..这里有太多奇怪的逻辑吗? 坚持下去,将帮助您理解这一点。
Line 1: Basic chain ruleLine 2: 1st and third term is on the lines of above calculations itself. Again spend a minute or do it on paper to understand this.
第1行:基本链规则第2行:第一项和第三项位于上述计算本身的行上。 再次花一点时间或在纸上做些了解。
Now, what the heck is this rotated w!? Took me a really long time to understand how this was calculated. For this, you need to go through these concepts in the mentioned order only.
现在,旋转了w !到底是什么? 我花了很长时间了解它是如何计算出来的。 为此,您只需要按照上述顺序来研究这些概念。
Transposed Convolution — Output is [1*1 matrix] and XX is [1*4 matrix (because was flattened here)], right. So, when we backpropagate, we are increasing the size of the matrix. Transpose convolution helps in this. Fast forward the video and just see the logic where they are taking transpose convolution.
转置卷积-输出为[1 * 1矩阵],而XX为[1 * 4矩阵(因为此处已展平)),右。 因此,当我们反向传播时,我们正在增加矩阵的大小。 转置卷积对此有所帮助。 快进视频,然后看看他们进行转置卷积的逻辑。
Now take a deep breath, and read through this. This is the most important one to understand the intuition for calculating how output changes with filter and X. Pasting the conclusion from the above article. JFYI, don’t get confused from Full convolution, its nothing but Transpose convolution (which you just understood above).
现在深呼吸,并通过阅读此。 这是理解用于计算输出如何随filter和X改变的直觉的最重要的一个。粘贴以上文章中的结论。 JFYI,不要对全卷积感到困惑,它只不过是转置卷积(您在上面刚刚了解了)。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/fab529f7ac69bbd08b4cb5b3a57dd73d.png)
Conclusively, we can decrease Filter and w value as this.
最终,我们可以这样降低Filter和w值。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/be351d004ac5e0aa8b5aeda90a630160.png)
场景2 – 2个卷积层+ 1个全连接层(Scenario 2– 2 Convolution Layer + 1 Fully Connected Layer)
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/883aeb6c7675070ed9612fa672f13a02.png)
Now, add as many layer of convolution, our approach will remain the same. As usual, the goal would be:
现在,添加尽可能多的卷积层,我们的方法将保持不变。 与往常一样,目标是:
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/82aa09e24652c548538ecd71109653ec.png)
First 2 terms we have already calculated above. Let’s see what will be the formula for the last term.
我们已经在上面计算了前两个项。 让我们来看看上学期的公式。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/b9ca81b6826ec050e6499d1b2b09865f.png)
In case you need to deep dive into this. I would recommend this article. And calculate new F1, F2 and w accordingly.
如果您需要深入了解这一点。 我会推荐这篇文章。 并据此计算新的F1,F2和w。
方案3-最大池层怎么办? (Scenario 3— What about Max Pooling layer??)
Max Pooling is an important concept of the CNN and how does back propagation work for it?
最大池化是CNN的重要概念,反向传播如何工作?
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/fa4449722a948bd4d4cf597ca6b954ff.png)
If you think about it, there are no variables in max pooling layer like filters. So, we don’t need to adjust any value here.
如果您考虑一下,在最大池化层中没有像过滤器这样的变量。 因此,我们无需在此处调整任何值。
But, it’s affecting my previous layers, right?! It’s reducing the size of matrix by combining few entries in a matrix to a single digit. Basically, it does affect backpropagation. It says that values that have non-maximum value won’t have any gradient.
但是,它正在影响我以前的图层,对吗? 通过将矩阵中的几个条目组合成一个数字,可以减小矩阵的大小。 基本上,它确实会影响反向传播。 它说具有非最大值的值将没有任何梯度。
So, what we are saying here is — All the values which doesn’t have maximum value will have 0 as their value. More depth.
因此,我们在这里所说的是-所有没有最大值的值都将以0作为其值。 更深入。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/82feff8302adef68c676d045d0b4e177.png)
Have tried to put all good and relevant articles in one place, and to help you see the overall picture of convolution. Please go through the above and let me know if something still stands missing in the overall flow — will be happy to edit it to accommodate the same.
试图将所有好的和相关的文章放在一个地方,并帮助您了解卷积的整体情况。 请仔细阅读以上内容,并让我知道整体流程中是否仍缺少某些内容,我们很乐意对其进行修改以适应相同的情况。
翻译自: https://towardsdatascience.com/convolution-neural-network-maths-intuition-6b047cb48e90
卷积神经网络数学原理