본문 바로가기
인공지능 (기본 딥러닝)/딥러닝 및 파이토치 기타 정리

[Pytorch] 모델 생성시, super().__init__()

by 애플파ol 2023. 11. 1.

파이토치를 활용해서 모델을 만들면 항상

Super(class명, self).__init__()   =   Super().__init__() 

를 해주었는데 어떤 기능을 하는건지 확인을 해보았다. 

(뒤의 두개는 같은 기능임)

import torch.nn as nn  # Neural Network, activation function 모듈의 기본 클래스
import torch

class model_name(nn.Moudle):
	def__init__(self):
    	super(model_name,self).__init__()
        	
        self.layer_1=nn.Linear(
                    in_features=32,
                    out_features=16
                    )
            
    def forward(self,x):
    	x=self.layer_1(x)
        
        return x

 

➢  부모 클래스 nn.Module의 것들을 상속받아서 우리가 만든 model에서 사용하는 것이다. 

 

공홈을 들어가서  확인을 해보니 아래와 같은것을 상속받는것을 확인할수 있었다. 

(https://pytorch.org/docs/stable/_modules/torch/nn/modules/module.html#Module)