【Pytorch】ModuleList和Sequential和List的区别

  • 文档:torch.nn.ModuleList, Sequential, List
  • ModuleList和List类似,是nn.Module的子类,能够和List一样的索引方式进行所以,但是没有实现forward方法,其中存储的元素自动识别为Module,如果直接用List的话,程序看不到里面的参数之类的东西,训练时会报错。ModuleList can be indexed like a regular Python list, but modules it contains are properly registered, and will be visible by all Module methods.
  • Sequential实现了forward方法,要注意各个module之间的channel要对应起来。

参考:stackflow

猜你喜欢

转载自blog.csdn.net/BubbleCodes/article/details/124836575