Pytorch建模技巧总结
发布时间
阅读量:
阅读量
####1、模型参数的存储与调用
(A)参数存储
# 2 ways to save the net
torch.save(net1, 'net.pkl') # save entire net
torch.save(net1.state_dict(), 'net_params.pkl') # save only the parameters
(B)参数加载
# copy net1's parameters into net3
net3.load_state_dict(torch.load('net_params.pkl'))
prediction = net3(x)
上述所提及的net1与net3均为nn.Module类的具体实例。
####2、模型参数的限制
# Clip weights of discriminator
for p in discriminator.parameters():
p.data.clamp_(-opt.clip_value, opt.clip_value)
p作为Module(nn.Module)的一个实例,是鉴别器discriminator的参数。
全部评论 (0)
还没有任何评论哟~
