A residual connection adds a block’s input to its output, creating an information shortcut around noisy or destructive layers. It helps deep networks preserve information and propagate gradients when ordinary layer chains suffer from vanishing gradients. section 9.2
A residual block in R/Keras
inputs <- keras_input(shape = c(32, 32, 3)) x <- inputs |> layer_conv_2d(32, 3, activation = "relu") residual <- x x <- x |> layer_conv_2d(64, 3, activation = "relu", padding = "same") residual <- residual |> layer_conv_2d(64, 1) x <- layer_add(list(x, residual)) The 1 × 1 convolution projects the shortcut from 32 to 64 channels so both paths can be added. section 9.2
The pattern stores the incoming representation, processes a copy through the target block, then combines both paths with addition. If the block changes spatial size through max pooling, the shortcut uses a 1 × 1 convolution with matching strides.
Use residual connections with these practical checks:
- Match the input and output shapes before addition. section 9.2
- Use a 1 × 1 convolution to change channel count or downsample the shortcut. section 9.2
- Stack blocks to build deeper hierarchical models; residual paths make deeper optimization more feasible. section 9.1











