【发布时间】:2019-03-28 23:50:20
【问题描述】:
我正在尝试理解 TensorFlow 代码 sn-p。我被教导的是,我们将所有传入的输入相加,然后将它们传递给激活函数。下图中显示的是单个神经元。请注意,我们计算输入的加权和,然后计算激活。
在多层感知器的大多数示例中,它们不包括求和步骤。我觉得这很令人困惑。
这是其中一个 sn-ps 的示例:
weights = {
'h1': tf.Variable(tf.random_normal([n_input, n_hidden_1])),
'h2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])),
'out': tf.Variable(tf.random_normal([n_hidden_2, n_classes]))
}
biases = {
'b1': tf.Variable(tf.random_normal([n_hidden_1])),
'b2': tf.Variable(tf.random_normal([n_hidden_2])),
'out': tf.Variable(tf.random_normal([n_classes]))
}
# Create model
def multilayer_perceptron(x):
# Hidden fully connected layer with 256 neurons
layer_1 = tf.nn.relu(tf.add(tf.matmul(x, weights['h1']), biases['b1']))
# Hidden fully connected layer with 256 neurons
layer_2 = tf.nn.relu(tf.add(tf.matmul(layer_1, weights['h2']), biases['b2']))
# Output fully connected layer with a neuron for each class
out_layer = tf.nn.relu(tf.matmul(layer_2, weights['out']) + biases['out'])
return out_layer
在每一层中,我们首先将输入与weights 相乘。之后,我们添加 bias 术语。然后我们将它们传递给tf.nn.relu。求和发生在哪里?看起来我们已经跳过了这个!
任何帮助都会非常棒!
【问题讨论】:
-
据我了解是
softmax做的,相当于softmax = tf.exp(logits) / tf.reduce_sum(tf.exp(logits), axis) -
好的——softmax 层可以做到。但是其他节点不做呢?
-
不,我不这么认为,因为这没有任何意义,如果您求和或执行任何类型的聚合,它们将不再成为一个层,因此您无法将它们提供给另一个层跨度>
-
它仍然是一个层。层中的每个单独的神经元都接受输入,每个神经元必须产生一个标量值。
标签: python tensorflow machine-learning