09-19 11:58
Notice
Recent Posts
Recent Comments
반응형
관리 메뉴

BAN2ARU

[Python/ Pytorch] torch.nn.ModuleList() 본문

Language/Python

[Python/ Pytorch] torch.nn.ModuleList()

밴나루 2022. 4. 21. 16:15

https://pytorch.org/docs/stable/generated/torch.nn.ModuleList.html를 기반으로 작성하였음

 

CLASS
torch.nn.ModuleList(modules=None)

Submodule(conv,batchnorm 등 layer)을 list속에 담을 수 있음. 일반적인 python의 list와 유사하지만, torch.nn.module에서 확인 할 수 있음. Nerual network를 학습을 하기 위해서는 module list로 선언해주어야함. (일반 list로 구성시에는 torch.nn.module 메서드에서 확인이 불가능하므로, 학습이 되지 않음 - [1] 참조)


Parameters

  • modules (iterable, optional) : 추가할 모듈의 iterable (iterable : 하나씩 차례대로 member들을 retrun할 수 있는 object : list, str, tuple 등 - [2] 참조)

Etc

append(module)

 

list의 끝에 주어진 module을 apped함.

<Parameters>

  • module (nn.Module) - append할 모듈
extend(modules)

Python iterable의 모듈을 목록 끝에 추가함. ([3] 참조)

<Parameters>

  • modules (iterable) - append할 모듈의 iterable
insert (index, module)

list에서 주어진 index 앞에 주어진 module을 insert함. ([3] 참조)

<Parameters>

  • index (int) - insert할 index
  • module (nn.Module) - insert할 module

Reference

[0] https://pytorch.org/docs/stable/generated/torch.nn.ModuleList.html

[1] https://hongl.tistory.com/279

[2] https://bluese05.tistory.com/55

[3] https://ooyoung.tistory.com/117

728x90
Comments