参考文档Module — PyTorch 1.7.0 documentation

1  @torch.no_grad()
2  def init_weights(m):
3      print(m)
4      if type(m) == nn.Linear:
5          m.weight.fill_(1.0)
6          print(m.weight)
7  net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
8  net.apply(init_weights)

net类及其子类都会调用 init_weights() 方法

相关文章:

  • 2021-09-18
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2022-12-23
  • 1970-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案