你的意思是你想得到 conv1 层的权重值。
您实际上还没有使用 conv2d 定义权重,您需要这样做。当我创建一个卷积层时,我使用一个执行所有必要步骤的函数,这里是我用来创建每个卷积层的函数的复制/粘贴:
def _conv_layer(self, name, in_channels, filters, kernel, input_tensor, strides, dtype=tf.float32):
with tf.variable_scope(name):
w = tf.get_variable("w", shape=[kernel, kernel, in_channels, filters],
initializer=tf.contrib.layers.xavier_initializer_conv2d(), dtype=dtype)
b = tf.get_variable("b", shape=[filters], initializer=tf.constant_initializer(0.0), dtype=dtype)
c = tf.nn.conv2d(input_tensor, w, strides, padding='SAME', name=name + "c")
a = tf.nn.relu(c + b, name=name + "_a")
print name + "_a", a.get_shape().as_list(), name + "_w", w.get_shape().as_list(), \
"params", np.prod(w.get_shape().as_list()[1:]) + filters
return a, w.get_shape().as_list()
这是我用来定义 5 个卷积层的方法,这个示例直接来自我的代码,所以请注意,它是 5 个卷积层堆叠而成,没有使用最大池或任何东西,步长为 2 和 5x5 内核。
conv1_a, _ = self._conv_layer("conv1", 3, 24, 5, self.imgs4d, [1, 2, 2, 1]) # 24.8 MiB/feature -> 540 x 960
conv2_a, _ = self._conv_layer("conv2", 24, 80, 5, conv1_a, [1, 2, 2, 1]) # 6.2 MiB -> 270 x 480
conv3_a, _ = self._conv_layer("conv3", 80, 256, 5, conv2_a, [1, 2, 2, 1]) # 1.5 MiB -> 135 x 240
conv4_a, _ = self._conv_layer("conv4", 256, 750, 5, conv3_a, [1, 2, 2, 1]) # 0.4 MiB -> 68 x 120
conv5_a, _ = self._conv_layer("conv5", 750, 2048, 5, conv4_a, [1, 2, 2, 1]) # 0.1 MiB -> 34 x 60
tensorflow 网站上也有关于如何设置卷积网络的很好的教程:
https://www.tensorflow.org/tutorials/deep_cnn
您的问题的直接答案是卷积层的权重在那里定义为w,如果我理解正确,这就是您要问的张量。