Pytorch的nn.Module类中定义的实例方法apply()


参考文档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() 方法


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM