Count the Parameters
A network is a chain of nn.Linear layers, and sizes lists the sizes along it: [4, 8, 2] is a layer from 4 to 8 followed by a layer from 8 to 2. Return how many numbers the network learns in all: every weight and every bias.
Example 1
sizes [4,8,2]
returns 58
4 times 8 weights and 8 biases, then 8 times 2 weights and 2 biases: 40 + 18.
Constraints
- 2 to 5 sizes, each from 1 to 9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More PyTorch problems
- Cross-EntropyMedium
- Fit a LineMedium
- How Often RightMedium
- In BatchesMedium
- Many OutputsMedium
- Mean Squared ErrorMedium
- One Step DownhillMedium
- Two LayersMedium