Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从tf.contrib.layers.conv2d切换到tf.nn.conv2d_Python_Tensorflow - Fatal编程技术网

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')