Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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
在TensorFlow中使用输入作为卷积滤波器_Tensorflow - Fatal编程技术网

在TensorFlow中使用输入作为卷积滤波器

在TensorFlow中使用输入作为卷积滤波器,tensorflow,Tensorflow,我习惯于在Tensorflow中使用习得的过滤器,应用于输入数据(或前一层的输出) nn.conv2d的输入形状是[h,w,in\u channels,out\u channels],如果我的数据是[?,n1,n2,1](第一维度是小批量大小),那么我会使用形状作为conv2d[h,w,1,m]其中m是我想学习的过滤器数量 但是有可能将输入本身用作过滤器吗?也就是说,我不想为minibatch的每个片段学习相同的过滤器,而是想为每个片段使用不同的过滤器——一个直接从输入派生的过滤器,我不学习 例

我习惯于在Tensorflow中使用习得的过滤器,应用于输入数据(或前一层的输出)

nn.conv2d
的输入形状是
[h,w,in\u channels,out\u channels]
,如果我的数据是
[?,n1,n2,1]
(第一维度是小批量大小),那么我会使用
形状作为
conv2d
[h,w,1,m]
其中
m
是我想学习的过滤器数量

但是有可能将输入本身用作过滤器吗?也就是说,我不想为minibatch的每个片段学习相同的过滤器,而是想为每个片段使用不同的过滤器——一个直接从输入派生的过滤器,我不学习

例如,如果我的输入数据由两部分组成,它们都是2D,我的minibatch为5,例如。
D1=[[1,2]、[3,4]、[5,6]、[7,8]、[9,0]。

D1=[[0,1],[2,0],[3,2],[8,1],[0,0]]

然后,我想执行
[1,2]
[0,1]
的卷积,以及
[3,4]
[2,0]
的卷积等(在我的例子中,尺寸是合适的,这只是一个演示)

是否可以使用
nn.conv2d
执行此操作?如果没有,是否可以使用
扫描
或任何其他方式


谢谢。

在您的例子中,您所说的“从输入导出的带滤波器的卷积”基本上是元素级乘法,然后是一个reduce操作。例如,您可以执行以下操作:

sess = tf.InteractiveSession()
D1 = tf.constant([ [1,2] , [3,4] , [5,6] , [7,8] , [9,0] ])
D2 = tf.constant([ [0,1] , [2,0] , [3,2] , [8,1] , [0,0] ])

# Element-wise multiply D1 and D2, then reduce along dimension 1
result = tf.reduce_sum(D1 * D2, reduction_indices=[1])

print(result.eval())
# prints [ 2  6 27 64  0]

在您的例子中,您所谓的“从输入导出的带过滤器的卷积”基本上是元素级乘法,然后是一个reduce操作。例如,您可以执行以下操作:

sess = tf.InteractiveSession()
D1 = tf.constant([ [1,2] , [3,4] , [5,6] , [7,8] , [9,0] ])
D2 = tf.constant([ [0,1] , [2,0] , [3,2] , [8,1] , [0,0] ])

# Element-wise multiply D1 and D2, then reduce along dimension 1
result = tf.reduce_sum(D1 * D2, reduction_indices=[1])

print(result.eval())
# prints [ 2  6 27 64  0]

这只是一个例子-在我的例子中,我确实有矩阵,我需要执行卷积。请指定要卷积的两个操作数的形状。大小可以更改。卷积是在一个m x n矩阵和一个k x n滤波器上执行的(kIt只是一个例子-在我的例子中,我确实有矩阵,我需要执行卷积。请指定要卷积的两个操作数的形状。大小可以更改。卷积是在一个m x n矩阵和一个k x n滤波器(k)上执行的