我最近一直在玩神经网络及其在应用程序中的用途。就在最近,我遇到了一个描述神经网络的教程,该教程将学习如何对0-9(MNIST)中的手写数字进行分类。我遇到问题的教程中的代码部分低于(https://pythonprogramming.net/tensorflow-neural-network-session-machine-learning-tutorial/)
def neural_network_model(data):
hidden_1_layer = {'weights':tf.Variable(tf.random_normal([784, nodes_hl1])),
'biases':tf.Variable(tf.random_normal([nodes_hl1]))}
hidden_2_layer = {'weights':tf.Variable(tf.random_normal([nodes_hl1, nodes_hl2])),
'biases':tf.Variable(tf.random_normal([nodes_hl2]))}
hidden_3_layer = {'weights':tf.Variable(tf.random_normal([nodes_hl2, nodes_hl3])),
'biases':tf.Variable(tf.random_normal([nodes_hl3]))}
output_layer = {'weights':tf.Variable(tf.random_normal([nodes_hl3, n_classes])),
'biases':tf.Variable(tf.random_normal([n_classes])),}
l1 = tf.add(tf.matmul(data,hidden_1_layer['weights']), hidden_1_layer['biases'])
l1 = tf.nn.relu(l1)
l2 = tf.add(tf.matmul(l1,hidden_2_layer['weights']), hidden_2_layer['biases'])
l2 = tf.nn.relu(l2)
l3 = tf.add(tf.matmul(l2,hidden_3_layer['weights']), hidden_3_layer['biases'])
l3 = tf.nn.relu(l3)
output = tf.matmul(l3,output_layer['weights']) + output_layer['biases']
return output
我对发生的事情有基本的把握。 3个隐藏层是一组通过偏差和权重连接的节点。最终输出层是神经网络的结果。我理解这里的一切,除了包含tf.nn.relu()的代码行。在查看TensorFlow的文档之后,它提到的全部功能是计算功能的整齐线性(https://www.tensorflow.org/api_docs/python/nn/activation_functions_#relu)。我对这个函数的执行情况以及它在神经网络中的重要性感到困惑。
答案 0 :(得分:1)
relu(整流线性单元)的一些优点