Convolutions

In this section, we will learn about convolutions. We're going to see the structure of a convolutional network, and then we're going to apply that to two dimensions, just like we would if we were using it for an image. Finally, we're going to discuss the benefits of a convolutional network and why you would choose to use one.

Alright, let's get started! First, we're going to import the networkx packages and matplotlib, just like we did for the classical neural network:

Importing packages

The code here is similar to what we learned in the previous chapter, but there's a minor change:

Connecting from the inputs to the activation

You will have noticed that where we are connecting from the inputs to the activation, rather than connecting every input to every activation, we have a window. In this case, we're using a window of three, and that window then makes a sparser set of connections. The sparser set of connections, as you can see here in the actual image, means that not every input is connected to every activation; instead, there's a sliding window:

Sliding window

If you look at the lower left-hand dot, you'll see that it's actually connected one, two, three up, down to the first activation in the next column, and then similarly one, two, three up, down to the second dot in the second column. Here, we're going to visualize just a part of a network. We have a 6 x 6 grid of pixels connecting to a 6 x 6 grid of activations; so we're going to walk up the x and the y here in steps of 3. This means that this is a 3 x 3 subpatch. As you can see from the arc lines that are drawn in the output graph, what's happening is that the 3 x 3 grid and the lower left is actually being connected to one pixel on the activation on the right:

Visualizing a part of a network

The output of the preceding code is as follows:

Output—visualizing a part of a network

This is different, very much so compared to the dense neural network, because it is connecting multiple inputs to a single output, as opposed to every input to every output. Using this, you can visualize how, across a larger image, this patch would slide across the image encoding regions into output variables. This has special benefits for image processing that we'll discuss now.

So, why do we do this? Regions. Convolutional neural networks encode regions of images, much like you'd think of how you look at an image with your eyes. This has important computational benefits because it groups the x and y regions of an image together computationally, creating a compact representation of the data; it's much more efficient to process a convolutional neural network because there are simply less connections to compute. Now, convolutional neural networks are not only more accurate, but they, by and large, run faster.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.75.165