如何绘制连接到3个不同过滤器的权重?

时间:2019-06-08 02:37:13

标签: python numpy tensorflow

我在CNN中使用了一个卷积层和一个完全连接层。其中有两个输出节点。我在卷积层(一维卷积)中使用一个输入通道和3个滤波器通道。当我存储完全连接层的最终权重矩阵时,它的形状为(36,2)。而单个输入具有12个功能。现在,我想分别绘制附加到第一通道,第二通道和第三通道的滤波器权重。如果我绘制前12个权重,是否表示它们对应于第一个通道的1类?

`
def weight_variable(shape):
    initial = tf.truncated_normal(shape, mean=0, stddev=0.1)
    return tf.Variable(initial)

def conv1d(input, filter):
    return tf.nn.conv1d(input, filter, stride=1, padding='SAME')

x = tf.placeholder(tf.float32, [None, FLAGS.image_width])
y_ = tf.placeholder(tf.float32, [None, 2])

input = tf.reshape(x, [-1, FLAGS.image_width, FLAGS.input_channel])
filter = weight_variable([FLAGS.filter_width,  FLAGS.input_channel, 
FLAGS.filter_channel])

conv_out = tf.nn.tanh(conv1d(input, filter))



#Fully_Connected_layer
dim = conv_out.get_shape().as_list()

conv_re = tf.reshape(conv_out, (-1, dim[1]*dim[2]))
W_fc = weight_variable([dim[1]*dim[2], 2])
logits = tf.matmul(conv_re, W_fc)
y_prime = tf.nn.softmax(logits)


#Cross_entropy:
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits, 
labels= y_)
loss = tf.reduce_mean(cross_entropy)
optimizer = tf.train.GradientDescentOptimizer(FLAGS.rLearn).minimize(loss)


#Check_predictions:
correct_prediction = tf.equal(tf.argmax(y_prime, axis=1),tf.argmax(y_, 
axis=1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))`




`W = W.eval()  #shape (36,2)
W1 = W[0:12,0]
W2 = W[12:24,0]
W3 = W[24:36,0]`

0 个答案:

没有答案