我一直在跟着这个用TensorFlow编写的卷积神经网络示例进行编码,但是我对这些权重的分配感到困惑:
weights = {
# 5x5 conv, 1 input, 32 outputs
'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])),
# 5x5 conv, 32 inputs, 64 outputs
'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])),
# fully connected, 7*7*64 inputs, 1024 outputs
'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])),
# 1024 inputs, 10 outputs (class prediction)
'out': tf.Variable(tf.random_normal([1024, n_classes]))
}
我们怎么知道'wd1'权重矩阵应该有7 x 7 x 64行?
之后它被用来重新塑造第二个卷积层的输出:
# Fully connected layer
# Reshape conv2 output to fit dense layer input
dense1 = tf.reshape(conv2, [-1, _weights['wd1'].get_shape().as_list()[0]])
# Relu activation
dense1 = tf.nn.relu(tf.add(tf.matmul(dense1, _weights['wd1']), _biases['bd1']))
根据我的计算,池化层2(conv2输出)有4 x 4 x 64个神经元。
为什么我们要将其重新整形为[-1,7*7*64]?
PADDING=same
,因此感到困惑。谢谢! - jfbeltran_X
的维度是[28x28x1]
?不应该是[28x28]
吗?为什么有额外的x1
? - daniel451