Here is the rigorous, complete guide addressing the Master Formula, the exact relationship between same padding and stride, and the full standard pipeline (Conv2D, Pooling, Dense) alongside all potential surprises (padding="valid", padding="same", use_bias=False, BatchNormalization, UpSampling2D, and Receptive Field).

Every single type follows the exact exam structure: Python code, role, input/output shapes using the Master Formula, filter tensor shapes, number of neurons in layers with learnable parameters, and total learnable parameters.


1. The True Master Formulas & Padding Conventions

Let:

  • = input spatial size (height or width)
  • = output spatial size
  • = filter size ( in slides, )
  • = stride
  • = total padding added across both sides ( if symmetric)

The Universal Master Equation (Valid for ANY Convolution & Pooling):


Important: Why same does NOT always equal

In modern frameworks (Keras/TensorFlow), the definition of padding="same" is that the output spatial dimension matches the input downsampled by the stride :

  • Case 1: When :
  • Case 2: When (e.g., ):
  • Total Padding applied under the hood to achieve this:

2. Per-Type Breakdown (Standard & Surprise Layers)


Type 1: Conv2D with padding="same" and (Standard)

# Input from previous layer: (28, 28, 2)
model.add(layers.Conv2D(16, (3, 3), strides=(1, 1), padding="same", activation="relu"))
  • Role: Extracts 16 local spatial feature maps while maintaining full spatial resolution ().
  • Input Shape:
  • Output Shape Formula: (Padding required: per side. Applying Master Formula: ).
  • Filter Tensor Shape:
  • Neurons in this Layer:
  • Learnable Parameters Formula:

Type 2: Conv2D with padding="valid" ()

# Input from previous layer: (28, 28, 2)
model.add(layers.Conv2D(16, (3, 3), strides=(1, 1), padding="valid", activation="relu"))
  • Role: Extracts 16 spatial feature maps without zero-padding; boundaries naturally shrink.
  • Input Shape:
  • Output Shape Formula:
  • Filter Tensor Shape:
  • Neurons in this Layer:
  • Learnable Parameters Formula:

Type 3: Conv2D with padding="same" and Strided Downsampling ()

# Input: (28, 28, 16)
model.add(layers.Conv2D(32, (3, 3), strides=(2, 2), padding="same", activation="relu"))
  • Role: Downsamples and extracts higher-level features simultaneously, replacing a pooling layer.
  • Input Shape:
  • Output Shape Formula:
  • Filter Tensor Shape:
  • Neurons in this Layer:
  • Learnable Parameters Formula:

Type 4: Conv2D with No Bias (use_bias=False)

# Input: (14, 14, 16)
model.add(layers.Conv2D(32, (3, 3), strides=(1, 1), padding="same", use_bias=False, activation="relu"))
  • Role: Standard spatial convolution without additive bias intercepts (used before BatchNorm).
  • Input Shape:
  • Output Shape Formula:
  • Filter Tensor Shape:
  • Neurons in this Layer:
  • Learnable Parameters Formula (Drop the bias term):

Type 5: Pooling (MaxPooling2D / AveragePooling2D)

# Input: (28, 28, 16)
model.add(layers.MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
  • Role: Reduces spatial dimensionality via non-parametric pooling (e.g., max or average); grants translation invariance.
  • Input Shape:
  • Output Shape Formula (Slide Rule): (Via Master Formula with : ).
  • Filter Tensor Shape: None (fixed mathematical operation).
  • Neurons in this Layer: (contains no learnable parameters).
  • Learnable Parameters:

Type 6: Flatten + Dense Layer (Standard vs. use_bias=False)

# Input tensor from Conv/Pool: (14, 14, 32)
model.add(layers.Flatten())
model.add(layers.Dense(128, activation="relu"))
  • Role of Flatten: Reshapes a 3D volume into a 1D vector:
  • Role of Dense: Full matrix multiplication connecting all input units to 128 hidden neurons with non-linear activation.
  • Dense Input Shape:
  • Dense Output Shape:
  • Filter Tensor Shape: None (Weight matrix ).
  • Neurons in this Layer:
  • Learnable Parameters Formulas:
    • Standard (use_bias=True, default):
    • Surprise (use_bias=False):

Type 7: Batch Normalization (BatchNormalization)

# Input: (14, 14, 32)
model.add(layers.BatchNormalization())
  • Role: Normalizes channel distributions across mini-batches; applies learnable affine transform ().
  • Input Shape:
  • Output Shape: (Dimensions never change)
  • Filter Tensor Shape: None.
  • Neurons with Learnable Parameters: (Normalizes incoming feature maps).
  • Parameters Formulas:
    • Trainable Parameters ():
    • Non-trainable Parameters (running ):
    • Total Parameters:

Type 8: Spatial Upsampling (UpSampling2D) & U-Net Skip Connection

# Decoder path: Input is (14, 14, 32)
model.add(layers.UpSampling2D(size=(2, 2)))
  • Role: Nearest-neighbor spatial expansion used in decoders / U-Net architectures to restore resolution.
  • Input Shape:
  • Output Shape Formula:
  • Filter Tensor Shape: None.
  • Neurons in this Layer:
  • Learnable Parameters:

(If concatenated with an encoder skip-connection tensor of shape via layers.Concatenate(axis=-1): output becomes with parameters).


3. Receptive Field (RF) Master Formulation

The receptive field () measures the sub-region of the initial input that influences a single neuron at layer .

Recursive Master Formulas:

  • Base conditions: ,
  • = filter/kernel size at layer (for Conv or Pool)
  • = stride at layer
  • = cumulative stride / jump

Example Walkthrough:

  • Input: ,
  • Layer 1 (Conv2D: ):
  • Layer 2 (MaxPool: ):
  • Layer 3 (Conv2D: ): (The neuron has an receptive field on the original image).

4. Master Calculation Matrix for the Exam

Layer TypeConfigurationOutput Spatial Size ()Output Channels ()Learnable Parameters Formula
Conv2Dpadding="valid"Filters count
Conv2Dpadding="same"Filters count
Conv2Duse_bias=FalseDepends on paddingFilters count
Pool2DMax / AvgUnchanged ()
UpSample2Dsize=(U, U)Unchanged ()
Denseuse_bias=True— units
Denseuse_bias=False— units
BatchNormDefaultUnchangedUnchanged ()Trainable:
Non-trainable: