本文整理汇总了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)