Chapter 3
Chapter 3
activation functions
between layers
INTRODUCTION TO DEEP LEARNING WITH PYTORCH
f(x) = max(x, 0)
In PyTorch:
relu = nn.ReLU()
In PyTorch:
Increasing the number of hidden layers = increasing the number of parameters = increasing
the model capacity
total = 0
Manually calculating the number of
for parameter in model.parameters():
parameters:
total += parameter.numel()
first layer has 4 neurons, each neuron has print(total)
8+1 parameters = 36 parameters
46
second layer has 2 neurons, each neuron
has 4+1 parameters = 10 parameters
total = 46 learnable parameters
Two parameters:
learning rate: controls the step size
Layer outputs can explode if inputs and weights are not normalized
Weights can be initialized using different methods (e.g., with a uniform distribution)
import torch
new_layer = torch.load('layer.pth')
Rule of thumb: freeze early layers of network and fine-tune layers closer to output layer
import torch.nn as nn