我一直沿着这个例子在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‘权矩阵应该有7x7x64行?
它后来被用来重塑第二个卷积层的输出:
# 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输出)有4x4x64个神经元。
为什么我们要重塑到-1,7*7*64
发布于 2016-01-07 20:30:03
从一开始就工作:
输入,_X大小为[28x28x1] (忽略批处理维度)。28x28灰度图像。
第一个卷积层使用PADDING=same,因此它输出一个28x28层,然后将该层传递给带有k=2的max_pool,该层将每个维度减少2倍,从而得到14x14的空间布局。conv1有32个输出,所以每个例子的全部张量现在是[14x14x32]。
这是在conv2中重复的,它有64个输出,从而产生一个[7x7x64]。
tl;dr:图像从28x28开始,每一个最大池在每个维度中将其减少2倍。28/2/2 = 7
发布于 2016-10-03 23:19:41
这个问题要求你对深造的卷积有一个很好的理解。
基本上,您的模型中的每个卷积层都将减少卷积金字塔的横截面面积。这个缩减是由卷积步长和max_pooling stride进行的。让事情变得更复杂的是,我们有两个基于填充的选项。
备选方案1- PADDING='SAME'
out_height = ceil(float(in_height) / float(strides[1]))
out_width = ceil(float(in_width) / float(strides[2]))备选方案2- PADDING='VALID'
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))对于,每个卷积和最大池调用,您将不得不计算一个新的out_height和out_width。然后,在卷积结束时,将最后一个卷积层的out_height、out_width和深度相乘。这个乘法的结果是输出特征映射大小,这是您的第一个完全连接层的输入。
因此,在您的示例中,您可能只有PADDING='SAME',卷积步长为1,最大池步长为2,为。最后,你只需将一切除以4 (1,2,1,2)。
更多信息请访问tensorflow API
https://stackoverflow.com/questions/34662443
复制相似问题