欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2022年03月24日 16:33:35   作者:sigmoidAndRELU  
今天看源碼時(shí)遇到的這個(gè)恒等函數(shù),就如同名字那樣占位符,并沒有實(shí)際操作,下面這篇文章主要給大家介紹了關(guān)于python中torch.nn.identity()方法的相關(guān)資料,需要的朋友可以參考下

先看代碼

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,輸出也是,并且給定的參數(shù)似乎并沒有起到變化的效果。

看源碼

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

這相當(dāng)?shù)暮啙嵜髁税?,輸入是啥,直接給輸出,不做任何的改變。再看文檔中的一句話:A placeholder identity operator that is argument-insensitive.

翻譯一下就是:不區(qū)分參數(shù)的占位符標(biāo)識(shí)運(yùn)算符。百度翻譯,其實(shí)意思就是這個(gè)網(wǎng)絡(luò)層的設(shè)計(jì)是用于占位的,即不干活,只是有這么一個(gè)層,放到殘差網(wǎng)絡(luò)里就是在跳過連接的地方用這個(gè)層,顯得沒有那么空虛!

應(yīng)用

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

總結(jié)

到此這篇關(guān)于python中torch.nn.identity()方法的文章就介紹到這了,更多相關(guān)python torch.nn.identity()方法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論