Okay, let's calculate the number of parameters for each layer in the mlp_model.
A Dense (fully connected) layer has two sets of parameters:
- Weights: The number of weights is
(number_of_input_features * number_of_units_in_layer).
- Biases: The number of biases is
(number_of_units_in_layer).
Total parameters for a Dense layer = (input_features * units) + units.
Let's break it down layer by layer:
-
layers.Input(shape=(784,)): This layer defines the input shape but has 0 parameters itself. The input dimension is 784.
-
layers.Dense(1048, activation='relu'):
- Input features = 784 (from the Input layer)
- Units in this layer = 1048
- Weights = 784 * 1048 = 821,552
- Biases = 1048
- Total Parameters = 821,552 + 1048 = 822,600
-
layers.Dense(128, activation='relu'):
- Input features = 1048 (from the previous Dense layer)
- Units in this layer = 128
- Weights = 1048 * 128 = 134,144
- Biases = 128
- Total Parameters = 134,144 + 128 = 134,272
-
layers.Dense(64, activation='relu'):
- Input features = 128 (from the previous Dense layer)
- Units in this layer = 64
- Weights = 128 * 64 = 8,192
- Biases = 64
- Total Parameters = 8,192 + 64 = 8,256
-
layers.Dense(64, activation='relu'):
- Input features = 64 (from the previous Dense layer)
- Units in this layer = 64
- Weights = 64 * 64 = 4,096
- Biases = 64
- Total Parameters = 4,096 + 64 = 4,160
-
layers.Dense(64, activation='relu'):
- Input features = 64 (from the previous Dense layer)
- Units in this layer = 64
- Weights = 64 * 64 = 4,096
- Biases = 64
- Total Parameters = 4,096 + 64 = 4,160
-
layers.Dense(10, activation='softmax'):
- Input features = 64 (from the previous Dense layer)
- Units in this layer = 10
- Weights = 64 * 10 = 640
- Biases = 10
- Total Parameters = 640 + 10 = 650
Total Number of Parameters:
Sum the parameters from all layers:
822,600 + 134,272 + 8,256 + 4,160 + 4,160 + 650 = 974,098
The neural network has a total of 974,098 parameters.