Introduction to Deep Learning with PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
# Create network with three linear layers model = nn.Sequential(nn.Linear(n_features, 8),nn.Linear(8, 4), nn.Linear(4, n_classes))
nn.Sequential() are hidden layers# Create network with three linear layers
model = nn.Sequential(
nn.Linear(n_features, 8), # n_features represents number of input features
nn.Linear(8, 4),
nn.Linear(4, n_classes) # n_classes represents the number of output classes
)
nn.Sequential() are hidden layersn_features and n_classes are defined by the dataset



# Create network with three linear layers
model = nn.Sequential(
nn.Linear(10, 18),
nn.Linear(18, 20),
nn.Linear(20, 5)
)
# Create network with three linear layers
model = nn.Sequential(
nn.Linear(10, 18), # Takes 10 features and outputs 18
nn.Linear(18, 20),
nn.Linear(20, 5)
)
# Create network with three linear layers
model = nn.Sequential(
nn.Linear(10, 18),
nn.Linear(18, 20), # Takes 18 and outputs 20
nn.Linear(20, 5)
)
# Create network with three linear layers
model = nn.Sequential(
nn.Linear(10, 18),
nn.Linear(18, 20),
nn.Linear(20, 5) # Takes 20 and outputs 5
)
$$

$$
$$

$$
$$

$$
$$

$$

$$

$$
Manual parameter calculation:
$$

$$
Manual parameter calculation:
$$

$$
Manual parameter calculation:
$$

$$
Manual parameter calculation:
$$

$$
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