Flattening

So far, we've focused on building as condensed and expressive a representation of our features as possible and used convolutional neural networks and max pooling layers to do this. The last step of our transformation is to flatten our convolved and max-pooled ndarray, in our example a 2 x 2 matrix, into a single row of training data.

Our max-pooled diagonal black line example would look something like the following, in code:

import numpy as np
max_pooled = np.array([[255,255],[255,255]])

max_pooled

Running this code returns the following output:

We can check the shape here by running the following:

max_pooled.shape

This returns this output:

To turn this matrix into a single training sample, we just run flatten(). Let's do this and look at the shape of our flattened matrix:

flattened = max_pooled.flatten()
flattened.shape

This generates the following output:

What started as a 5 x 5 matrix of pixel intensities is now a single row with four features. We can now pass this into a fully-connected neural network.

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

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