我有信号维度= (样本,高度,宽度,通道)和内核维度= ( filter_height,filter_width,in_channels,out_channels)在卷积操作中使用它们:
tf.nn.conv2d(signal, kernel, strides=[1, 1, 1, 1], padding="VALID")
但是, width = filter_width 和频道 = in_channels 因为我使用的是文字的信号即可。我要检查的是,如果我使用多声道信号与在宽度维度中连接多声道信号并作为一个声道信号操作(如下图所示)相同但输出不同甚至共享内核值。为了更好地解释,我在这里复制一些代码:
import tensorflow as tf
sess = tf.InteractiveSession()
samples = 2
n = 10
We = 5
filter_size = 4
num_filters = 20
embedding1 = tf.Variable(tf.truncated_normal([samples,n,We,1], stddev=0.1))
embedding2 = tf.Variable(tf.truncated_normal([samples,n,We,1], stddev=0.1))
multi_X = tf.concat([embedding1, embedding2], 3)#shape=(2, 10, 5, 2)
concat_X = tf.concat([embedding1, embedding2], 2)#shape=(2, 10, 10, 1)
W1 = tf.Variable(tf.truncated_normal([filter_size, We, 1, num_filters], stddev=0.1))
W2 = tf.Variable(tf.truncated_normal([filter_size, We, 1, num_filters], stddev=0.1))
multi_W = tf.concat([W1, W2], 2)#shape=(4, 5, 2, 20)
concat_W = tf.concat([W1, W2], 1)#shape=(4, 10, 1, 20)
multi_conv = tf.nn.conv2d(multi_X, multi_W, strides=[1, 1, 1, 1], padding="VALID")#shape=(2, 7, 1, 20)
concat_conv = tf.nn.conv2d(concat_X, concat_W, strides=[1, 1, 1, 1], padding="VALID")#shape=(2, 7, 1, 20)
init_op = tf.global_variables_initializer()
sess.run(init_op)
#sess.run(multi_conv) == sess.run(concat_conv) may be True