函数named_parameters(),返回各层中参数名称和数据
class MLP(nn.Module):
def __init__(self):
super(MLP, self).__init__()
self.hidden = nn.Sequential(
nn.Linear(256,64),
nn.ReLU(inplace=True),
nn.Linear(64,10)
)
def forward(self, x):
return self.hidden(x)
#x = torch.randperm(256*2).view(-1,256)
net = MLP()
net(x

本文介绍PyTorch中Module模块的named_parameters()函数,该函数用于获取模型中所有参数的名称及其对应的数值,对于理解和调试深度学习模型的参数非常有用。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



