TensorFlow:如何将两个神经网络层合理地合并成一个?

3

假设有一个简单的神经网络具有两个输入Tensorflow:

W0 = tf.Variable(tf.zeros([784, 100]))
b0 = tf.Variable(tf.zeros([100]))
h_a = tf.nn.relu(tf.matmul(x, W0) + b0)

W1 = tf.Variable(tf.zeros([100, 10]))
b1 = tf.Variable(tf.zeros([10]))
h_b = tf.nn.relu(tf.matmul(z, W1) + b1)
问题: 如何将这两个层合并成下一层的一个好方法?
我是指像这样的东西: h_master = tf.nn.relu(tf.matmul(concat(h_a, h_b), W_master) + b_master) 然而,我似乎找不到一个合适的函数来实现这个。
编辑: 请注意:如果我这样做: h_master = tf.nn.tanh(tf.matmul(np.concatenate((h_a,h_b)),W_master) + b_master)
我会得到以下错误:
ValueError: zero-dimensional arrays cannot be concatenated

我的猜测是,这是因为NumPy将占位符视为空数组,因此h_a和h_b都是零维的。
1个回答

2

我找到了一种方法:

h_master = tf.nn.tanh(tf.matmul(tf.concat((h_a, h_b), axis=1), W_master) + b_master)

where:

W_master = tf.Variable(tf.random_uniform([110, 10], -0.01, 0.01))
b_master = tf.Variable(tf.zeros([10]))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接