Introduction to Deep Learning with PyTorch
Maham Faisal Khan
Senior Data Scientist
n_features
n_classes
model = nn.Sequential(nn.Linear(n_features, 8),
nn.Linear(8, 4),
nn.Linear(4, n_classes))
We can use as many hidden layers as we want
Increasing the number of hidden layers = increasing the number of parameters = increasing the model capacity
Given the following model:
model = nn.Sequential(nn.Linear(8, 4),
nn.Linear(4, 2))
Manually calculating the number of parameters:
Using PyTorch:
.numel()
: returns the number of elements in the tensortotal = 0
for parameter in model.parameters():
total += parameter.numel()
print(total)
46
Introduction to Deep Learning with PyTorch