top of page

Convolutional Neural Network

Characteristics​​​

  1. A type of neural network

  2. Typically used on pictures

Depiction of a CNN

Screen Shot 2020-06-08 at 4.10.13 PM.png

How to code a CNN

Analysis of the Structure

  1. It can be seen that ReLu is used in this network along with softmax. 

  2. Pooling maps a region of an image in order to identify different features of an image. 

  3. Softmax is used to identify the probability of what this image is (logistic regression)

1. Import any needed libraries

Screen Shot 2020-06-08 at 4.20.13 PM.png

   2. Import all training and testing images

Screen Shot 2020-06-08 at 4.20.22 PM.png

​   3. Reshape any needed arrays or clean the needed data:

Screen Shot 2020-06-08 at 4.21.03 PM.png

    4. If needed, convert each image to a float between 0 and 225 and then between a 0-1 (in python colors are identified as three numbers all varying from 0 to 225):​

Screen Shot 2020-06-08 at 4.21.11 PM.png

​   5. ​Convert the Y values to categorical values (similar to one hot encoding)​

Screen Shot 2020-06-08 at 4.21.31 PM.png

   6. ​Create the network​, add ReLu layers, and the final softmax layers

Screen Shot 2020-06-08 at 4.21.51 PM.png

   7. Compile the network

Screen Shot 2020-06-08 at 4.22.04 PM.png

   8. Train the model and print the results

Screen Shot 2020-06-08 at 4.22.28 PM.png

9. Set an array of what the CNN predicted for each image (this isn’t required but is just interesting to look at).

  • Note: Predict_proba returns the probability estimate (softmax)

  • Predict_classes returns what actual value/category the model returned

Screen Shot 2020-06-08 at 4.22.59 PM.png
bottom of page