[英]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.