本文整理匯總了Python中torch.legacy方法的典型用法代碼示例。如果您正苦於以下問題:Python torch.legacy方法的具體用法?Python torch.legacy怎麽用?Python torch.legacy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch
的用法示例。
在下文中一共展示了torch.legacy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init
# 需要導入模塊: import torch [as 別名]
# 或者: from torch import legacy [as 別名]
def init(mods):
global convI, fcI
for m in mods:
if isinstance(m, legacy.nn.SpatialConvolution):
m.weight = convs[convI]
convI += 1
elif isinstance(m, legacy.nn.Linear):
m.weight = fcs[fcI]
fcI += 1
elif isinstance(m, legacy.nn.Concat) or \
isinstance(m, legacy.nn.Sequential):
init(m.modules)
示例2: printM
# 需要導入模塊: import torch [as 別名]
# 或者: from torch import legacy [as 別名]
def printM(mods):
for m in mods:
if isinstance(m, legacy.nn.SpatialConvolution):
print('Conv2d norm: {}'.format(torch.norm(m.output)))
elif isinstance(m, legacy.nn.Linear):
pass
elif isinstance(m, legacy.nn.Concat) or \
isinstance(m, legacy.nn.Sequential):
printM(m.modules)
# printM(net_th.modules)
示例3: getM
# 需要導入模塊: import torch [as 別名]
# 或者: from torch import legacy [as 別名]
def getM(mods):
for m in mods:
if isinstance(m, legacy.nn.SpatialConvolution):
m.gradWeight[m.gradWeight.ne(m.gradWeight)] = 0
l.append(torch.norm(m.gradWeight))
elif isinstance(m, legacy.nn.Linear):
l.append(torch.norm(m.gradWeight))
elif isinstance(m, legacy.nn.Concat) or \
isinstance(m, legacy.nn.Sequential):
getM(m.modules)