【PyTorch】教程:torch.nn.CELU

torch.nn.CELU

原型

CLASS torch.nn.CELU(alpha=1.0, inplace=False)

参数

  • inplace (bool, optional) – 可选的是否为内部处理. 默认为 False
  • alpha (float) – CELU 公式里的值,默认为 1.0

定义

CELU ( x ) = max ⁡ ⁡ ( 0 , x ) + min ⁡ ⁡ ( 0 , α ∗ ( exp ⁡ ⁡ ( x / α ) − 1 ) ) \text{CELU}(x)=\max⁡(0,x)+\min⁡(0, \alpha∗(\exp⁡(x/\alpha)−1)) CELU(x)=max(0,x)+min(0,α(exp(x/α)1))

在这里插入图片描述

代码

import torch
import torch.nn as nn

m = nn.CELU()
input = torch.randn(4)
output = m(input)

print("input: ", input)    # input:  tensor([ 0.1335,  0.9612, -0.3477, -0.5911])
print("output: ", output)  # output:  tensor([ 0.1335,  0.9612, -0.2937, -0.4463])

【参考】

CELU — PyTorch 1.13 documentation

猜你喜欢

转载自blog.csdn.net/zhoujinwang/article/details/129482505