简体   繁体   English

在 Keras 中使用“selu”激活函数时出错

[英]Error using 'selu' activation function with Keras

I'm using Keras with Tensorflow backend.我正在使用带有 Tensorflow 后端的 Keras。 When I'm trying to use the 'selu' activation function using:当我尝试使用“selu”激活函数时:

model.add(Dense(32, input_shape=(input_length - 1,)))
model.add(Activation('selu'))

The error I get is:我得到的错误是:

ValueError: Unknown activation function:selu

Is there any solution to this?有什么解决办法吗?

Selu is not in your activations.py of keras (most likely because it was added Jun 14, 2017, only 22 days ago). Selu 不在您的 keras activations.py中(很可能是因为它是在 2017 年 6 月 14 日添加的,仅在22 天前)。 You can just add the missing code in the activations.py file or create your own selu activation in the script.您可以只在activations.py文件中添加缺少的代码或在脚本中创建您自己的selu激活。

Example code示例代码

from keras.activations import elu

def selu(x):
    """Scaled Exponential Linear Unit. (Klambauer et al., 2017)
    # Arguments
        x: A tensor or variable to compute the activation function for.
    # References
        - [Self-Normalizing Neural Networks](https://arxiv.org/abs/1706.02515)
    """
    alpha = 1.6732632423543772848170429916717
    scale = 1.0507009873554804934193349852946
    return scale * elu(x, alpha)

model.add(Dense(32, input_shape=(input_length - 1,)), activation=selu)

NOTE:笔记:

With tensorflow 2.0 keras is included.包含 tensorflow 2.0 keras。 You can get the selu activation with:您可以通过以下方式获得 selu 激活:

from tensorflow.keras.activations import selu

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SeLU 激活函数 x 参数导致类型错误 - SeLU Activation Function x-Parameter causes a typeError Keras - 人工神经网络 - 使用自定义激活时出错 function - Keras – Artificial Neural Networks - Error when using a custom activation function 绕过Keras的激活功能 - Round an activation function in Keras 在 Keras 中使用自定义步骤激活 function 会导致“'tuple' object has no attribute '_keras_shape'”错误。 如何解决这个问题? - Using a custom step activation function in Keras results in “'tuple' object has no attribute '_keras_shape'” error. How to resolve this? 在Keras中使用自定义步骤激活功能会导致“操作没有梯度梯度的操作”错误。 如何解决呢? - Using a custom step activation function in Keras results in “An operation has `None` for gradient.” error. How to resolve this? Keras 给出错误:ValueError: ('无法解释激活函数标识符:' - Keras give error: ValueError: ('Could not interpret activation function identifier:' Keras 中的“无法解释激活 function 标识符:256”错误 - "Could not interpret activation function identifier: 256" error in Keras 绘制使用Keras中现有功能定义的新激活功能 - Plotting a new activation function defined using an existing one from Keras Keras CuDNNLSTM 隐式激活函数? - Keras CuDNNLSTM implicit activation function? Keras自定义激活功能(不是培训) - Keras custom activation function (not training)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM