日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python中torch.nn.identity()方法詳解_python

作者:sigmoidAndRELU ? 更新時間: 2022-05-27 編程語言

先看代碼

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])

這是官方文檔中給出的代碼,很明顯,沒有什么變化,輸入的是torch,輸出也是,并且給定的參數似乎并沒有起到變化的效果。

看源碼

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

這相當的簡潔明了啊,輸入是啥,直接給輸出,不做任何的改變。再看文檔中的一句話:A placeholder identity operator that is argument-insensitive.

翻譯一下就是:不區(qū)分參數的占位符標識運算符。百度翻譯,其實意思就是這個網絡層的設計是用于占位的,即不干活,只是有這么一個層,放到殘差網絡里就是在跳過連接的地方用這個層,顯得沒有那么空虛!

應用

例如此時:如果此時我們使用了se_layer,那么就SELayer(dim),否則就輸入什么就輸出什么(什么都不做)

總結

原文鏈接:https://blog.csdn.net/TTLoveYuYu/article/details/118224298

欄目分類
最近更新