A linear layer, represented here by Keras's Dense layer, connects every unit to the preceding layer's outputs. In a CNN, flatten the extracted features before passing them through a dense layer; the final dense layer produces class outputs. section 7.1
A practical CNN head can use the following sequence:
- Flatten the reduced convolutional feature maps. section 7.1
- Add a Dense layer with 128 neurons and ReLU activation. section 7.1
- Add a final Dense layer with 10 outputs for the classes. section 7.1
The layer's width is an architecture choice. When architectures are encoded as gene sequences, a dense-layer block marks the layer and stores its neuron count; generated models can then rebuild that choice. section 7.2
CNN classification head
A Sequential model finishes its convolution and pooling stack with Flatten(), Dense(128, activation='relu'), and Dense(10). A generated architecture can represent a dense layer with a marker followed by a neuron count, such as -4, 25. section 7.1 section 7.2
Listing 7.4 EDL_7_1_Keras_CNN.ipynb: Finishing the model
model.add(layers.Flatten()) #1 model.add(layers.Dense(128, activation='relu')) #2 model.add(layers.Dense(10)) #3 model.summary()
Inspect the compact Keras implementation that adds the flattening step and two dense layers. section 7.1
Listing 7.10 EDL_7_2_Encoding_CNN.ipynb: Examining the generated gene sequence
individual = create_offspring() #1 print(individual) [-1, 37, 5, 2, -3, -1, 112, 4, 2, -4, 25] #2
Inspect a generated gene sequence containing a dense-layer marker and its encoded neuron count. section 7.2












