Week 07 · Convolutions and residual connections
Calculate a receptive field and compare a stack with an identity path.
← Week 6 · Subject contents · Week 8 →
Calculate a receptive field and compare a stack with an identity path.
Work through the problem
Two width-three convolutions with stride one and no dilation give a receptive field of five. The first combines three adjacent input positions. The second combines three adjacent outputs whose input windows overlap. Padding changes border inputs but does not expand the theoretical footprint.
For a residual block y=x+F(x), the local Jacobian is I+J_F. A plain stack multiplies the Jacobians of every layer. If a scalar filter has weight 0.5, eight layers give gain 0.5⁸. If the residual branch instead has gain 0.01, the corresponding eight blocks give gain 1.01⁸. An identity path helps preserve signals, although it does not guarantee stable training.
Run the Python lab
import torch
from torch.nn.functional import conv1d
x = torch.arange(9.).reshape(1,1,9)
kernel = torch.ones(1,1,3)
print("Two convolutions:", conv1d(conv1d(x,kernel),kernel).flatten().tolist())
for residual in [False,True]:
signal = torch.tensor(1.,requires_grad=True)
y = signal
for _ in range(8):
y = y+.01*y if residual else .5*y
y.backward()
print("Residual",residual,"gradient",round(signal.grad.item(),5))
Output from the lab
Two convolutions: [18.0, 27.0, 36.0, 45.0, 54.0]
Residual False gradient 0.00391
Residual True gradient 1.08286
Practice
- How wide is the receptive field after a third width-three layer?
Check your reasoning
- Seven positions at stride one.
← Week 6 · Subject contents · Week 8 →
Further reading · Goodfellow, Bengio, and Courville · Deep Learning