We have seen how a Sequential model can be used to create an image classification model for MNIST. Let's look at how we can look at convolutional APIs along with the functional APIs. We will explore convolutional APIs from Keras in a later part of the book, so here we focus on the functional aspects of the APIs.
Let's first look at how we will build the model from the input of MNIST images coming in batches:
input_shape = (28, 28) inputs = Input(input_shape) print(input_shape + (1, )) # add one more dimension for convolution x = Reshape(input_shape + (1, ), input_shape=input_shape)(inputs) conv1 = Conv2D(14, kernel_size=4, activation='relu')(x) pool1 = MaxPooling2D(pool_size=(2, 2))(conv1) conv2 = Conv2D(7, kernel_size=4, activation='relu')(pool1) pool2 = MaxPooling2D(pool_size=(2, 2))(conv2) flatten = Flatten()(pool2) output = Dense(10, activation='sigmoid')(flatten) model = Model(inputs=inputs, outputs=output)
We start with the...