【PyTorch】教程:torch.nn.PReLU

torch.nn.PReLU

原型

CLASS torch.nn.PReLU(num_parameters=1, init=0.25, device=None, dtype=None)

参数

  • num_parameters ([int]) – 需要学习的 a a a 的数量,尽管作为输入,只有两个值是合法的,1 或者 输入的通道数,默认为 1
  • init ([float]) – a a a 的初始值,默认为 0.25

定义

PReLU ( x ) = max ⁡ ( 0 , x ) + a ∗ min ⁡ ( 0 , x ) \text{PReLU}(x)= \max(0, x) + a * \min(0, x) PReLU(x)=max(0,x)+amin(0,x)

or

PReLU ( x ) = { x , if x ≥ 0 a x , otherwise \text{PReLU}(x) = \begin{cases} x, & \text{if} x \geq 0 \\ ax, & \text{otherwise} \end{cases} PReLU(x)={ x,ax,ifx0otherwise

在这里插入图片描述

代码

import torch
import torch.nn as nn

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

print("input: ", input)   # input:  tensor([ 0.1061, -2.0532,  1.4081, -0.1516])
print("output: ", output) # output:  tensor([ 0.1061, -0.5133,  1.4081, -0.0379], grad_fn=<PreluBackward>)

【参考】

PReLU — PyTorch 1.13 documentation

猜你喜欢

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