In this lecture, we are going to continue our discussion on alternative perspectives of convolution.
Again, this is very helpful for understanding convolution, but it doesn't teach you anything new mechanically.
So this lecture is optional if you want to just move on and learn about how to make science.
So in this lecture, what were you going to talk about as the equivalence of convolution and a matrix
multiplication?
In other words, in what scenario are they actually the same thing?
Let's do an example.
This is easier to see if we only do a one dimensional conversation.
So let's first go over how that would work.
This should be easy since two dimensional convolution is just a generalization of this.
So let's start with a one dimensional image.
A equals A1, A2 a three eight four.
We also have filter w equals W1 W2.
Then the convolution output will be B, which is a convulsed with W, and the elements are A1 times
one plus a two times W two, a two times W one plus a three times W two and a three times W one plus
four times W two.
So in general, we can write one dimensional convolution as the sum from I prime equals one up to K
of eight I plus I prime times W of I prime.
You'll notice that this is the same equation we had for two dimensional convolution, just with the
second index dropped.
Using this, it's pretty easy to see how we would implement the same thing using matrix multiplication.
What we've done here is we created a matrix where we repeat the filter along each row, but on each
row we shift it to the right by one space.
Now I recommend you do this by hand so you can see that it works.
If you multiply the matrix by the original input vector A., You get the correct output of the convolution.
So what's the lesson here is that by repeating the same filter again and again inside a matrix, we
can implement convolution without actually doing convolution.
Instead, we can just use matrix multiplication.
But there is another problem with this particular method of doing matrix multiplication, and this is
that the equivalent matrix repeats the filter multiple times.
So the result is that the Matrix takes up a lot more space than the original filter, which was just
a two element array originally.
In other words, while this was a helpful perspective, you don't necessarily want to implement convolution
this way.
Instead, it's helpful to look at this from the opposite direction.
What if there are instances where instead of doing a faux matrix multiplication, we can replace it
with convolution?
This is the idea behind parameter sharing or weight sharing.
Think of it this way inside a neuron that we are constantly doing.
This operation equals W Transpose X.
Here is the output activation and X is the input feature.
Vector W is the weight matrix.
Well, what if instead of a full weight matrix, we just had the same two weights repeating over and
over again, then we have less parameters are known that work takes up less memory and ram, and thus
we can make the computation more efficient.
In other words, convolution saves both space and time by using less weights.
Why might we want to do this?
Consider what we did in the previous section where we had a fully connected neural network looking at
a single image.
Luckily, those images were just grayscale images of size 28 by 28, which gives us 784 features.
But what if we had a slightly larger image and had color?
The CFR 10 dataset is one such example.
Those images are 32 by 32 by three.
In this case, we have three thousand seventy two features.
That's quite a large increase from 784.
And keep in mind, a 32 by 32 image is quite modest in size, to say the least.
Modern CNN, such as Viji look at images of size 224 by 224.
If you use a full weight matrix, then you would have one hundred fifty thousand five hundred twenty
eight features.
Suppose you're looking at an image with modern HD resolution that's twelve eighty by 720.
In this case, you would have about 2.8 million features.
As you can imagine, this is much too large for a neural network.
But there's another good reason to use change, which is that you don't need different weights for each
part of the neural network.
Remember that convolution is actually correlation and the filter is really a pattern finer.
In this scenario, we actually want the same filter to look at all locations on the image.
This is the idea behind translational and variance.
Suppose we are building a dog versus cat, recognize it.
Here is an image containing a cat.
Here's another image containing a cat.
But what's the difference between these two images?
The only difference is that the cat is in a different position.
Now, if we use the fully connected or dense neural network, we would have to learn the weights for
each of these positions separately.
And on top of that, this nerve network won't generalize well because if we come across the same cat
but in a new position, the neural network would have failed to recognize it.
So in fact, it's better to have a shared pattern finder because this pattern finder looks at all locations
on the image.
You don't need to learn the weights to look at a cat at every single possible point, which would actually
be infeasible.