【PyTorch】教程:torch.nn.LeakyReLU
创始人
2024-05-31 01:12:04

torch.nn.LeakyReLU

原型

CLASS torch.nn.LeakyReLU(negative_slope=0.01, inplace=False)

参数

  • negative_slope (float) – 控制负值斜率,默认为 1e-2
  • inplace (bool) – in-place 操作,默认为 False

定义

LeakyReLU(x)=max⁡(0,x)+negative_slope∗min⁡(0,x)\text{LeakyReLU}(x) = \max(0, x) + \text{negative\_slope} * \min(0, x) LeakyReLU(x)=max(0,x)+negative_slope∗min(0,x)

or

LeakyReLU(x)={x,if x≥0negative_slope×x,otherwise \text{LeakyReLU}(x) = \begin{cases} x, & \text{ if } x \geq 0 \\ \text{negative\_slope} \times x, & \text{ otherwise } \end{cases} LeakyReLU(x)={x,negative_slope×x,​ if x≥0 otherwise ​

在这里插入图片描述

代码

import torch
import torch.nn as nnm = nn.LeakyReLU(0.1)
input = torch.randn(2)
output = m(input)print("input: ", input)    # input:  tensor([-1.5754,  0.6229])
print("output: ", output)  # output:  tensor([-0.1575,  0.6229])

【参考】

LeakyReLU — PyTorch 1.13 documentation

相关内容

热门资讯

苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...