【问题标题】:Switching from tf.contrib.layers.conv2d to tf.nn.conv2d从 tf.contrib.layers.conv2d 切换到 tf.nn.conv2d
【发布时间】:2018-09-07 17:21:39
【问题描述】:

到目前为止,我正在使用tf.contrib.layers.conv2d,但是(例如,允许使用here 讨论的权重衰减过滤器)我想切换到tf.nn.conv2d 实现。但是我对参数感到困惑,因为显然我需要指定之前没有指定的东西。

使用 doc 和 SO 条目,我试了一下。对于具有 [batch_size, x, y, channels] 的 4D-Tensors,这两个版本是否相同?即我是否正确假设 input_layer.shape[-1] 代表input_channels 所要求的filter 并且我必须明确地将步幅设置为我的输入张量的暗淡数量:

与 tf.contrib.layers.conv2d(原始)

down0a = tf.contrib.layers.conv2d(input_layer, n_features, (3, 3))
down0b = tf.contrib.layers.conv2d(down0a, n_features, (3, 3))
down0c = tf.contrib.layers.max_pool2d(down0b_do, (2, 2), padding='same')

与 tf.nn.conv2d

down0a = tf.nn.conv2d(input_layer, filter=[3, 3, input_layer.shape[-1], n_features], strides=[1, 1, 1, 1], padding='SAME')
down0ar = tf.nn.relu(down0a)
down0b = tf.nn.conv2d(down0ar, filter=[3, 3, down0ar.shape[-1], n_features], strides=[1, 1, 1, 1], padding='SAME')
down0br = tf.nn.relu(down0b)
down0c = tf.nn.max_pool(down0br, [2, 2, down0br.shape[-1], n_features], strides=[1, 1, 1, 1], padding='SAME')

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    你似乎得到了正确的形状,最明显的问题似乎是你不应该告诉tf.nn.conv2d形状,你应该将实际的重量张量传递给它。

    down0w = tf.get_variable("down0w", shape=[3, 3, input_layer.shape[-1], n_features], initializer=tf.contrib.layers.xavier_initializer())
    down0a = tf.nn.conv2d(input_layer, filter=down0w, strides=[1, 1, 1, 1], padding='SAME')
    

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 2018-11-08
      • 2010-10-10
      • 2017-02-06
      • 2018-11-04
      • 2011-10-26
      • 2010-10-19
      • 2014-04-25
      • 2015-09-18
      相关资源
      最近更新 更多