2

我想使用矩阵指定激活节点之间的连接性,而不是完全连接的层。例如:

我有一个连接到 10 节点层的 20 节点层。使用典型的全连接层,我的W矩阵为 20 x 10,b向量大小为 10。

我的激活看起来像relu(Wx + b)

如果我有一个大小相同的 1 和 0 矩阵W,可以调用它F,我可以在第一层(20 个节点)和第二层(10 个节点)之间进行成对乘法WF删除连接

这是我当前的代码:

F.shape
# (20, 10)
import tflearn
import tensorflow as tf

input = tflearn.input_data(shape=[None, num_input])

first = tflearn.fully_connected(input, 20, activation='relu')
# Here is where I want to use a custom function, that uses my F matrix
# I dont want the second layer to be fully connected to the first, 
# I want only connections that are ones (and not zeros) in F

# Currently:
second = tflearn.fully_connected(first, 10, activation='relu')
# What I want:
second = tflearn.custom_layer(first, my_fun)

my_fun 给我的地方:relu( (FW)X + b)并且FW是成对乘法

如何创建此功能?我似乎无法找到关于它是如何完成的 tflearn 示例,但我也知道 tflearn 也允许基本 tensorflow 函数

4

1 回答 1

1

严格使用 tflearn 很难做到这一点,但如果你愿意包含基本的 tensorflow 操作,它很简单:

F.shape
# (20, 10)
import tflearn
import tensorflow as tf

input = tflearn.input_data(shape=[None, num_input])
tf_F = tf.constant(F, shape=[20, 10])

first = tflearn.fully_connected(input, 20, activation='relu')
# Here is where I want to use a custom function, that uses my F matrix
# I want only connections that are ones (and not zeros) in F

# Old:
# second = tflearn.fully_connected(first, 10, activation='relu')
# Solution:
W = tf.Variable(tf.random_uniform([20, 10]), name='Weights')
b = tf.Variable(tf.zeros([10]), name='biases')
W_filtered = tf.mul(tf_F, W)
second = tf.matmul( W_filtered, first) + b
于 2017-01-28T18:50:49.837 回答