在基本神经网络中整流线性函数的作用

我最近一直在探索神经网络及其在应用程序中的应用。就在不久前,我看到一个教程,描述了一个神经网络,它可以学习如何对从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

我对其中的基本操作有了一定的了解。这三个隐藏层各是一组由偏置和权重连接的节点。最终的输出层是神经网络的结果。我理解这里的所有内容,除了包括tf.nn.relu()的代码行。查看了TensorFlow的文档后,它只提到该函数计算特征的整流线性。我对这个函数的作用及其在神经网络中的重要性感到相当困惑。


回答:

整流线性单元(ReLU)的优势包括

  • 计算成本较低(因此性能更好)
  • 其他一些函数如sigmoid容易饱和
  • 它们的导数易于计算(记住训练过程依赖于导数)

请查看此链接 https://www.quora.com/What-are-the-benefits-of-using-rectified-linear-units-vs-the-typical-sigmoid-activation-function

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注