【发布时间】:2017-09-07 03:44:52
【问题描述】:
我正在尝试实现一个未完全连接的层。我有一个矩阵,它在变量connectivity_matrix 中指定了我想要的连通性,这是一个由 1 和 0 组成的 numpy 数组。
我目前试图隐含层的方式是通过将权重两两乘以这个连接矩阵F:
这是在 tensorflow 中执行此操作的正确方法吗?这是我到目前为止所拥有的
import numpy as np
import tensorflow as tf
import tflearn
num_input = 10
num_layer1 = 313
num_output = 700
# For example:
connectivity_matrix = np.array(np.random.choice([0, 1], size=(num_layer1, num_output)), dtype='float32')
input = tflearn.input_data(shape=[None, num_input])
# Here is where I specify the connectivity in tensorflow
connectivity = tf.constant(connectivity_matrix, shape=[num_layer1, num_output])
# One basic, fully connected layer
layer1 = tflearn.fully_connected(input, num_layer1, activation='relu')
# Here is where I want to have a non-fully connected layer
W = tf.Variable(tf.random_uniform([num_layer1, num_output]))
b = tf.Variable(tf.zeros([num_output]))
# so take a fully connected W, and do a pairwise multiplication with my tf_connectivity matrix
W_filtered = tf.mul(connectivity, W)
output = tf.matmul(layer1, W_filtered) + b
【问题讨论】: