liveBook · Manning

Kernel size

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

Kernel size is the spatial extent of a convolutional filter applied by a convolutional layer.

Kernel size is the spatial extent of a convolutional filter, expressed as dimensions such as 3×3. In a CNN, it is a layer hyperparameter that shapes how convolution processes image data. section 7.1.1 section 7.2

Kernel size appears in several practical architecture decisions:

  • Keras passes it to Conv2D as a tuple, such as (3, 3), alongside the filter count and padding. section 7.1.1
  • Architecture encodings store convolutional kernel dimensions as genes alongside the number of filters or neurons. section 7.2
  • Pooling has its own spatial-size settings, allowing experiments to compare kernel-size changes with pooling changes or additional convolutional layers. section 7.1.2 section 7.1.1
  • Evolutionary mutation can replace convolutional and pooling dimensions with random values constrained by configured minimum and maximum ranges. section 7.4

A kernel size in a Keras layer

The layer Conv2D(64, (3, 3), activation='relu', padding='same', input_shape=(28, 28, 1)) uses a 3×3 kernel with 64 filters. In the evolutionary encoding, the corresponding convolution block stores the filter count followed by two kernel dimensions, for example [-1, 37, 5, 2]. section 7.1.1 section 7.2

Listing 7.18 EDL_7_4_Mutation_CNN.ipynb: The mutate function
def mutate(part, layer_type):
  if layer_type == CONV_LAYER and len(part)==CONV_LAYER_LEN:           #1
    part[1] = int(part[1] * random.uniform(.9, 1.1))                   #2
    part[2] = random.randint(min_kernel, max_kernel)                   #3
    part[3] = random.randint(min_kernel, max_kernel)                   #3
  elif layer_type == POOLING_LAYER and len(part)==POOLING_LAYER_LEN:   #1
    part[1] = random.randint(min_kernel, max_kernel)                   #3
    part[2] = random.randint(min_kernel, max_kernel)                   #3
  elif layer_type == DENSE_LAYER and len(part)==DENSE_LAYER_LEN:       #1
    part[1] = int(part[1] * random.uniform(.9, 1.1))                   #2
  else:
    error = f"mutate ERROR {part}"                                     #4
    raise Exception(error) 
  return part

Inspect the mutation implementation that changes convolutional kernel dimensions within configured bounds while validating the layer block. section 7.4

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

How deep it goes
Defines kernel dimensions through Keras code, gene encodings, configured ranges, and mutation logic without developing convolution mathematics.
Examples
Uses 3×3 Conv2D layers, encoded dimensions such as 5 and 2, and experiments that vary kernel, pooling, or layer settings.
What it assumes
Assumes familiarity with CNN layers and hyperparameters while encouraging trial-and-error exploration of architecture choices.
What you can do after
Apply it via Keras and evolutionary mutation code, then rerun models to inspect architecture and training-result changes.
How it connects
Connects kernel size to convolution, pooling, CNN architecture, hyperparameters, genetic algorithms, and Keras model construction.

Also explained in

Compare how 4 books explain kernel size →

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.