2. CNN Filter Terminology
Convolution filter strides all over the image which convolve the filter value with the over the pixels
of the image.
Stride:
• how many units you “shift” the filter (1/2/3/etc)
Padding:
• makes feature map same size as image
Kernel size:
• the dimensions of the filter (1x1, 3x3, 5x5, etc)
3/8/2024 Department of Biomedical Engineering, SRMIST, KTR 2
3. CNNs: Max Pooling Example
3/8/2024 Department of Biomedical Engineering, SRMIST, KTR 3
7. Components of a CNN
1) Specify the input layer
2) Add a convolution to create feature maps
3) Perform RELU on the feature maps
4) repeat 1) and 2)
5) add a FC (fully connected layer)
6) connect FC to output layer via softmax
3/8/2024 Department of Biomedical Engineering, SRMIST, KTR 7
8. CNN pseudocode
• Specify an optimiser
• specify a cost function
• specify a learning rate
• Specify desired metrics (accuracy/precision/etc)
• specify # of batch runs in a training epoch
• For each epoch: For each batch:
• Extract the batch data
• Run the optimiser + cross-entropy operations
• Add to the average cost
• Calculate the current test accuracy
• Print out some results
• Calculate the final test accuracy and print
3/8/2024 Department of Biomedical Engineering, SRMIST, KTR 8
9. CNN in Python/Keras (fragment)
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Flatten, Activation from
keras.layers.convolutional import Conv2D, MaxPooling2D
from keras.optimizers import Adadelta
input_shape = (3, 32, 32) nb_classes = 10 model = Sequential()
model.add(Conv2D(32, (3, 3), padding='same’, input_shape=input_shape))
model.add(Activation('relu')) model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25)
3/8/2024 Department of Biomedical Engineering, SRMIST, KTR 9