如何计算神经网络的连接数?附具体网络结构参数场景
Got it, let's break down the number of trainable parameters (which includes both weight connections and bias terms) for your neural network step by step—this is a common point of confusion, so let's unpack it clearly.
First, a quick clarification: when we talk about "connections" in this context, we’re referring to all trainable parameters: the weights that link neurons between layers, plus the bias terms for every neuron in non-input layers (as you specified, only the input layer skips biases).
Let’s go through each layer transition one by one:
1. Input Layer (784 units) → First Hidden Layer (400 units)
- Weight connections: Every neuron in the first hidden layer connects to every neuron in the input layer. That’s
784 * 400 = 313,600individual weights. - Bias terms: Each of the 400 hidden neurons has one bias term, so that’s
400biases. - Total for this segment:
313,600 + 400 = 314,000parameters.
2. First Hidden Layer (400 units) → Second Hidden Layer (200 units)
- Weight connections: Every neuron in the second hidden layer links to all 400 neurons in the first hidden layer. That’s
400 * 200 = 80,000weights. - Bias terms: 200 neurons mean
200bias terms. - Total for this segment:
80,000 + 200 = 80,200parameters.
3. Second Hidden Layer (200 units) → Output Layer (10 units)
- Weight connections: Each of the 10 output neurons connects to all 200 neurons in the second hidden layer. That’s
200 * 10 = 2,000weights. - Bias terms: 10 output neurons mean
10bias terms. - Total for this segment:
2,000 + 10 = 2,010parameters.
Total Trainable Parameters (Full Network)
Add up all the segments:314,000 + 80,200 + 2,010 = 396,210 total parameters.
Quick Formula to Verify
For any fully connected layer transition from a layer with n units to a layer with m units, the total parameters are (n * m) + m (weights plus biases). Applying this to each of your transitions gives the same result as above.
This should resolve the uncertainty—breaking it down layer by layer makes it easier to avoid missing biases or miscalculating weight counts.
内容的提问来源于stack exchange,提问作者haruishi

