liveBook · Manning

Linear layer

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

A dense layer is a neural-network layer in which each unit receives inputs from all units in the preceding layer.

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

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Shows Keras construction and neuron-count encoding, but does not derive the layer's mathematical internals.
Examples
Uses a Fashion-MNIST CNN head with 128 hidden neurons and 10 outputs, plus a gene sequence encoding a 25-neuron dense layer.
What it assumes
Assumes familiarity with CNN feature extraction and introduces dense-layer placement after flattening.
What you can do after
Build it from scratch via Keras and encode its neuron count for generated CNN architectures.
How it connects
Links dense layers with convolutional layers, pooling layers, flattening, and evolutionary architecture search.

Also explained in

Compare how 13 books explain linear layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.