Chapter 7: Computer Vision with Convolutional Neural Networks
Activity 13: Amending our Model with Multiple Layers and Use of SoftMax
Solution:
- Import the libraries and classes:
#Import the Libraries
from keras.models import Sequential from keras.layers import Conv2D from keras.layers import MaxPool2D from keras.layers import Flatten from keras.layers import Dense
- Now, initiate the model with a Sequential class:
#Initiate the classifier
classifier=Sequential()
- Add the first layer of the CNN, followed by the additional layers:
classifier.add(Conv2D(32,3,3,input_shape=(64,64,3),activation=’relu’))
classifier.add(Conv2D(32, (3, 3), activation = ‘relu’))
classifier.add(Conv2D(32, (3, 3), activation = ‘relu’))
32, (3,3) means that there are 32 feature detectors of size 3x3. As a best practice, always start with 32 and then you can add 64 or 128 later.
- Now, add the pooling layer with an image size of 2x2:
classifier.add(MaxPool2D(2,2))
- The...