栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

nn.PReLU(planes)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nn.PReLU(planes)

PReLU激活函数,内部源码实现

def __init__(self, num_parameters: int = 1, init: float = 0.25) -> None:
    self.num_parameters = num_parameters
    super(PReLU, self).__init__()
    self.weight = Parameter(torch.Tensor(num_parameters).fill_(init))

def forward(self, input: Tensor) -> Tensor:
    return F.prelu(input, self.weight)
def prelu(input, weight):
    # type: (Tensor, Tensor) -> Tensor
    r"""prelu(input, weight) -> Tensor

    Applies element-wise the function
    :math:`text{PReLU}(x) = max(0,x) + text{weight} * min(0,x)` where weight is a
    learnable parameter.

    See :class:`~torch.nn.PReLU` for more details.
    """
    if not torch.jit.is_scripting():
        if type(input) is not Tensor and has_torch_function((input,)):
            return handle_torch_function(prelu, (input,), input, weight)
    return torch.prelu(input, weight)

上边的公式搞到typora里就是如下形式:

weight这里是个可学习的参数,调用的时候nn.PReLU(planes)只输入了通道数,实现里将weight参数初始化为了0.25.

这和我们熟知的PRelu公式是一致的,

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665681.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号