keras.activations.softmax 和 keras.layers.Softmax 有什么区别?

keras.activations.softmaxkeras.layers.Softmax 有什么区别?为什么同一个激活函数有两个定义?

keras.activations.softmax: https://keras.io/activations/

keras.layers.Softmax: https://keras.io/layers/advanced-activations/


回答:

它们在功能上是等价的。实际上,Softmax 层在内部会调用 activations.softmax 函数

def call(self, inputs):    return activations.softmax(inputs, axis=self.axis)

然而,它们的区别在于,Softmax 层可以直接作为一个层使用:

from keras.layers import Softmaxsoft_out = Softmax()(input_tensor)

activations.softmax 不能直接作为一个层使用。相反,你可以通过 activation 参数将其传递给其他层的激活函数:

from keras import activationsdense_out = Dense(n_units, activation=activations.softmax)

此外,使用 Softmax 层的优点是它接受一个 axis 参数,你可以计算输入的另一个轴上的 softmax,而不是默认的最后一个轴:

soft_out = Softmax(axis=desired_axis)(input_tensor)

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中创建了一个多类分类项目。该项目可以对…

发表回复

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