Python 从tf.contrib.layers.conv2d切换到tf.nn.conv2d
到目前为止,我使用的是Python 从tf.contrib.layers.conv2d切换到tf.nn.conv2d,python,tensorflow,Python,Tensorflow,到目前为止,我使用的是tf.contrib.layers.conv2d,但是(例如,为了允许前面讨论的权重衰减过滤器),我想切换到tf.nn.conv2d实现。但是,我对参数感到困惑,因为显然我需要指定以前没有指定的内容 有了doc和SO条目,我尝试了一下。对于具有[batch_size,x,y,Channel]的4D张量,这两个版本是否相同?即,我是否正确地假设input_layer.shape[-1]表示输入_通道,如过滤器所需,并且我必须明确地将跨步设置为输入张量的DIM数: 带有tf.c
tf.contrib.layers.conv2d
,但是(例如,为了允许前面讨论的权重衰减过滤器),我想切换到tf.nn.conv2d
实现。但是,我对参数感到困惑,因为显然我需要指定以前没有指定的内容
有了doc和SO条目,我尝试了一下。对于具有[batch_size,x,y,Channel]的4D张量,这两个版本是否相同?即,我是否正确地假设input_layer.shape[-1]表示输入_通道
,如过滤器
所需,并且我必须明确地将跨步设置为输入张量的DIM数:
带有tf.contrib.layers.conv2d(原件)
使用tf.nn.conv2d
你似乎已经得到了正确的形状,最明显的问题似乎是你不应该告诉
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')
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')
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')