其他分享
首页 > 其他分享> > pytorch torch.nn.Identity()

pytorch torch.nn.Identity()

作者:互联网

torch.nn.Identity()

今天看源码时,遇到的这个恒等函数,就如同名字那样
占位符,并没有实际操作

源码:

class Identity(Module):
    r"""A placeholder identity operator that is argument-insensitive.
    Args:
        args: any argument (unused)
        kwargs: any keyword argument (unused)
    Examples::
        >>> m = nn.Identity(54, unused_argument1=0.1, unused_argument2=False)
        >>> input = torch.randn(128, 20)
        >>> output = m(input)
        >>> print(output.size())
        torch.Size([128, 20])
    """
    def __init__(self, *args, **kwargs):
        super(Identity, self).__init__()
 
    def forward(self, input: Tensor) -> Tensor:
        return input

主要使用场景:
不区分参数的占位符标识运算符

标签:__,torch,argument,unused,pytorch,input,Identity
来源: https://www.cnblogs.com/tian777/p/15349311.html