liveBook · Manning

Depth

As explained in Deep Learning with PyTorch, Second Edition

The extent to which a neural network has many stacked layers or sequential operations, increasing representational complexity.

Depth is the number of stacked layers or sequential operations in a neural network. Increasing it generally lets the network approximate more complex functions and recognize hierarchical structure, such as a person, face, and mouth in an image. section 8.5.3

Depth has two useful interpretations:

  • It adds representational complexity by composing increasingly detailed features. section 8.5.3
  • It lengthens the sequence of operations performed while processing an input, much like an algorithm. section 8.5.3
  • It can make training harder because long chains of derivative multiplications may cause gradients to vanish or become ineffective. section 8.5.3

From NetDepth to residual depth

A three-convolutional-layer NetDepth applies convolution, ReLU, and pooling sequentially. NetRes adds a skip connection, while NetResDeep repeats a residual block 100 times to construct a much deeper network. section 8.5.3

# In[57]:
class NetResDeep(nn.Module):
    def __init__(self, n_chans1=32, n_blocks=100):
        super().__init__()
        self.n_chans1 = n_chans1
        self.conv1 = nn.Conv2d(3, n_chans1, kernel_size=3, padding=1)
        self.resblocks = nn.Sequential(
            *(n_blocks * [ResBlock(n_chans=n_chans1)]))
        self.fc1 = nn.Linear(8 * 8 * n_chans1, 32)
        self.fc2 = nn.Linear(32, 2)
    def forward(self, x):
        out = F.max_pool2d(torch.relu(self.conv1(x)), 2)
        out = self.resblocks(out)
        out = F.max_pool2d(out, 2)
        out = out.view(-1, 8 * 8 * self.n_chans1)
        out = torch.relu(self.fc1(out))
        out = self.fc2(out)
        return out

Inspect a PyTorch implementation that builds depth by repeating residual blocks inside nn.Sequential. section 8.5.3

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Explains depth through intuition, sequential operations, gradient difficulties, and PyTorch architectures with up to 100 residual blocks.
Examples
Uses person-recognition hierarchies, three-layer NetDepth and NetRes models, residual blocks, and a 100-block network.
What it assumes
Assumes familiarity with width and backpropagation while explaining depth through accessible visual and algorithmic analogies.
What you can do after
Build deeper convolutional networks by stacking layers or repeating residual blocks in PyTorch.
How it connects
Connects depth to width, hierarchical information, backpropagation, skip connections, and residual connections.

Also explained in

Compare how 4 books explain depth →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.