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

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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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