gpt4 book ai didi

python - relu 作为 Dense() (或任何其他层)中的参数与 ReLu 作为 Keras 中的层

转载 作者:行者123 更新时间:2023-12-01 06:40:32 24 4
gpt4 key购买 nike

我只是想知道 的用途和专业之间是否有任何显着差异

Dense(activation='relu')

keras.layers.ReLu

后一个如何以及在哪里可以使用?我最好的猜测是在功能 API 用例中,但我不知道如何实现。

最佳答案

创建一些将激活作为参数传递的Layer实例,即activation='relu'与创建一些Layer实例然后创建相同激活,例如Relu 实例。 Relu() 是一个通过输入返回K.relu()函数的层:

class ReLU(Layer):
.
.
.
def call(self, inputs):
return K.relu(inputs,
alpha=self.negative_slope,
max_value=self.max_value,
threshold=self.threshold)

来自 Keras 文档:

Usage of activations

Activations can either be used through an Activation layer, or through the activation argument supported by all forward layers:

from keras.layers import Activation, Dense

model.add(Dense(64))
model.add(Activation('tanh'))

This is equivalent to:

model.add(Dense(64, activation='tanh'))

You can also pass an element-wise TensorFlow/Theano/CNTK function as an activation:

from keras import backend as K

model.add(Dense(64, activation=K.tanh))

更新:

回答OP的附加问题:如何以及在哪里使用后一个?:

当您使用某个层时,您可以使用它,该层不接受activation参数,例如tf.keras.layers.Addtf.keras.layers.Subtract 等,但您希望获得此类层的校正输出作为结果:

added = tf.keras.layers.Add()([x1, x2])
relu = tf.keras.layers.ReLU(added)

关于python - relu 作为 Dense() (或任何其他层)中的参数与 ReLu 作为 Keras 中的层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59476564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com