Number of Parameters in Neural Network
Sequence Models & Generative Models DS practice problem on Onlearn.
Difficulty: easy.
Topics: Number of Parameters in Neural Network, Dot Product, Chain Rule, Fully Connected Layers, Parameter Sharing, Floating Point Precision, Linear Algebra, Calculus, Neural Network Architecture, Optimization Theory, Computational Complexity, Matrix Operations, Backpropagation, Layer Connectivity, Weight Initialization, Memory Allocation.
Write a Python function that computes the total number of trainable parameters in a neural network given its architecture as a list of layer descriptions. Each layer is represented as a dictionary with a 'type' key indicating the layer type, along with other keys describing the layer's configuration. Supported layer types: 'dense': A fully connected layer with keys 'input size' (int), 'output size' (int), and optionally 'bias' (bool, defaults to True). 'conv2d': A 2D convolutional layer with keys 'in channels' (int), 'out channels' (int), 'kernel size' (int, representing a square kernel), and optionally 'bias' (bool, defaults to True). The function should return the total number of trainable parameters across all layers as an integer.