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 scenes.
So in this lecture, what we want to talk about is 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 convolution.
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 a one, two, three, four.
We also have a filter.
W equals W one.
W two.
Then the convolution output will be B, which is a key involved with W, and the elements are a one
times w one plus a two times w2a2 times w one plus a three times W two and a three times w one plus
a four times w two.
So in general we can write one dimensional convolution as the sum from ei prime equals one up to K of
at ei plus prime times w of prime.
You'll notice that this is the same equation we had for a 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?
It's 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 full 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 neural network, we are constantly doing this operation A equals W transpose
X Here A 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.
Our neural network takes up less memory in 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 gray scale images of size 28 by 28, which gives us 784 features.
But what if we had a slightly larger image and add color?
The key for ten data set is one such example.
Those images are 32 by 30, two by three.
In this case, we have 3072 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 scenes such as VG look at images of size 224 by 224.
If you use a full weight matrix, then you would have 150,528 features.
Suppose you're looking at an image with modern HD resolution that's 1280 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 is another good reason to use weight sharing, 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 finder.
In this scenario, we actually want the same filter to look at all locations on the image.
This is the idea behind Translational Invariance.
Suppose we are building a dog versus cat recognizer.
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 neural 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.