model.modules()和model.children()均为迭代器,model.modules()会遍历model中所有的子层,而model.children()仅会遍历当前层。

# model.modules()类似于 [[1, 2], 3],其遍历结果为:
[[1, 2], 3], [1, 2], 1, 2, 3
 
# model.children()类似于 [[1, 2], 3],其遍历结果为:
[1, 2], 3

用model.children()进行初始化参数时,可能会漏掉部分,用model.modules()会遍历所有层

参考链接:https://discuss.pytorch.org/t/module-children-vs-module-modules/4551

相关文章:

  • 2021-08-25
  • 2022-01-11
  • 2022-01-21
  • 2021-04-20
  • 2022-12-23
  • 2021-08-22
  • 2022-02-14
  • 2021-10-18
猜你喜欢
  • 2023-01-28
  • 2021-08-25
  • 2022-03-03
  • 2023-04-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
相关资源
相似解决方案