分類目錄:《深入淺出Pytorch函數(shù)》總目錄
相關(guān)文章:
· 深入淺出Pytorch函數(shù)——torch.nn.init.calculate_gain
· 深入淺出Pytorch函數(shù)——torch.nn.init.uniform_
· 深入淺出Pytorch函數(shù)——torch.nn.init.normal_
· 深入淺出Pytorch函數(shù)——torch.nn.init.constant_
· 深入淺出Pytorch函數(shù)——torch.nn.init.ones_
· 深入淺出Pytorch函數(shù)——torch.nn.init.zeros_
· 深入淺出Pytorch函數(shù)——torch.nn.init.eye_
· 深入淺出Pytorch函數(shù)——torch.nn.init.dirac_
· 深入淺出Pytorch函數(shù)——torch.nn.init.xavier_uniform_
· 深入淺出Pytorch函數(shù)——torch.nn.init.xavier_normal_
· 深入淺出Pytorch函數(shù)——torch.nn.init.kaiming_uniform_
· 深入淺出Pytorch函數(shù)——torch.nn.init.kaiming_normal_
· 深入淺出Pytorch函數(shù)——torch.nn.init.trunc_normal_
· 深入淺出Pytorch函數(shù)——torch.nn.init.orthogonal_
· 深入淺出Pytorch函數(shù)——torch.nn.init.sparse_
torch.nn.init
模塊中的所有函數(shù)都用于初始化神經(jīng)網(wǎng)絡(luò)參數(shù),因此它們都在torc.no_grad()
模式下運(yùn)行,autograd
不會(huì)將其考慮在內(nèi)。
該函數(shù)用單位矩陣填充二維輸入張量,其在線性層中保留盡可能多的輸入特征。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-667110.html
語(yǔ)法
torch.nn.init.eye_(tensor)
參數(shù)
-
tensor
:[Tensor
] 一個(gè)2維張量torch.Tensor
返回值
一個(gè)torch.Tensor
且參數(shù)tensor
也會(huì)更新文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-667110.html
實(shí)例
w = torch.empty(3, 5)
nn.init.eye_(w)
函數(shù)實(shí)現(xiàn)
def eye_(tensor):
r"""Fills the 2-dimensional input `Tensor` with the identity
matrix. Preserves the identity of the inputs in `Linear` layers, where as
many inputs are preserved as possible.
Args:
tensor: a 2-dimensional `torch.Tensor`
Examples:
>>> w = torch.empty(3, 5)
>>> nn.init.eye_(w)
"""
if tensor.ndimension() != 2:
raise ValueError("Only tensors with 2 dimensions are supported")
with torch.no_grad():
torch.eye(*tensor.shape, out=tensor, requires_grad=tensor.requires_grad)
return tensor
到了這里,關(guān)于深入淺出Pytorch函數(shù)——torch.nn.init.eye_的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!