PyTorch

torch.nn.Module

쉽게가자 2020. 5. 22. 21:54

파이토치에서 네트워크를 구현할 때 항상 torch.nn.Module을 상속받아 시작하는데, 정확히 어떻게 정의된 클래스인지 잘 모르는 상태로 코딩을 해왔다. 그래서 공식 문서에는 어떻게 적혀있나 살펴봤다.

https://pytorch.org/docs/stable/nn.html#containers

 

torch.nn — PyTorch 1.5.0 documentation

Shortcuts

pytorch.org

(torch.nn 페이지 중에 'Containers' 라는 카테고리에 들어있는데, Containers 라는건 또 뭘까?...)

일단 Module 클래스 자체의 설명은 이렇게 되어있다.


CLASStorch.nn.Module

    Base class for all neural network modules.

    Your models should also subclass this class.


모든 신경망 모델의 베이스 클래스이고, 모듈을 만들때는 반드시 이 크래스를 상속받아야한다고 적혀있다. 여기까진 기존에 생각했던 컨셉 그대로이다.