from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
Since there are F F D_in weights per filter, and the convolutional layer is composed of K filters, the total number of weights in the convolutional layer is K F F D_in. Since there is one bias term per filter, the convolutional layer has K biases. Thus, the number of parameters in the convolutional layer is given by K F F D_in + K.
K F F * D_in + K
Notice that H_in and W_in are the first and second value of the input_shape tuple, respectively.
The depth of the convolutional layer will always equal the number of filters K.
If padding = 'same', then the spatial dimensions of the convolutional layer are the following:
height = ceil(float(H_in) / float(S))
width = ceil(float(W_in) / float(S))
If padding = 'valid', then the spatial dimensions of the convolutional layer are the following:
height = ceil(float(H_in - F + 1) / float(S))
width = ceil(float(W_in - F + 1) / float(S))
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=2, strides=2, padding='valid',
activation='relu', input_shape=(200, 200, 1)))
model.summary()
model = Sequential()
model.add(Conv2D(filters=32, kernel_size=3, strides=2, padding='same',
activation='relu', input_shape=(128, 128, 3)))
model.summary()
Input has depth of 3 and it is increased to 16-32-64 in subsequent layers.
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=2, padding='same',
activation='relu', input_shape=(32, 32, 3)))
model.add(Conv2D(filters=32, kernel_size=2, padding='same', activation='relu'))
model.add(Conv2D(filters=64, kernel_size=2, padding='same', activation='relu'))
model.summary()
MaxPooling2D(pool_size, strides, padding) You must include the following argument:
pool_size - Number specifying the height and width of the pooling window.
strides - The vertical and horizontal stride. If you don't specify anything, strides will default to pool_size.
padding - One of 'valid' or 'same'. If you don't specify anything, padding is set to 'valid'.
model = Sequential()
model.add(MaxPooling2D(pool_size=2, strides=2, input_shape=(100, 100, 15)))
model.summary()
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=2, padding='same',
activation='relu', input_shape=(32, 32, 3)))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=32, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=64, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.summary()
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=2, padding='same',
activation='relu', input_shape=(32, 32, 3)))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=32, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=64, kernel_size=2, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Flatten())
model.add(Dense(500, activation='relu'))
model.add(Dense(10, activation='softmax'))
model.summary()