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
通过阅读源码可以看到,identity模块不改变输入。
直接return input
一种编码技巧吧,比如我们要加深网络,有些层是不改变输入数据的维度的,
在增减网络的过程中我们就可以用identity占个位置,这样网络整体层数永远不变,
看起来可能舒服一些,
可能理解的不到位。。。。