我在理解使用 TensorFlow 设置卷积神经网络时使用的张量的维度时遇到了一些困难。例如,在this https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html#build-a-multilayer-convolutional-network教程中,28x28 MNIST 图像表示如下:
import TensorFlow as tf
x = tf.placeholder(tf.float32, shape=[None, 784])
x_image = tf.reshape(x, [-1,28,28,1])
假设我有十个训练图像,上面的重塑使我的输入x_image
二十八个 28 维列向量的十个子集合的集合。
使用起来似乎更自然
x_image_natural = tf.reshape(x, [-1,28,28])
相反,它将返回 10 个 28x28 矩阵。
插图:
a = np.array(range(8))
opt1 = a.reshape(-1,2,2,1)
opt2 = a.reshape(-1,2,2)
print opt1
print opt2
# opt1 - column vectors
>>[[[[0]
>>[1]]
>>[[2]
>>[3]]]
>>[[[4]
>>[5]]
>>[[6]
>>[7]]]]
# opt2 - matrices
>>[[[0 1]
>>[2 3]]
>>[[4 5]
>>[6 7]]]
同样,是否有一种直观的方法来理解为什么卷积层具有维度(height_of_patch, width_of_patch, num_input_layers, num_output_layers)
?转置似乎更直观,因为它最终是补丁大小矩阵的集合。
* EDIT *
我其实很好奇why张量的维度按原样排序。
对于输入 X,我们为什么不使用
x_image = tf.reshape(x, [-1,i,28,28])
这将创建batch_size,i
- 大小的 28x28 矩阵数组(其中i
是输入层数)?
同样,为什么权重张量的形状不是这样的(num_output_layers, num_input_layers, input_height, input_width)
(这似乎更直观,因为它是“补丁矩阵”的集合。)