Deep Learning study

[Pytorch] torch.nn.Sequential 본문

AI/Pytorch api

[Pytorch] torch.nn.Sequential

HwaniL.choi 2018. 4. 2. 23:50
반응형
class torch.nn.Sequential(*args)[source]


편하게 순차적으로 실행하도록 담는 container라고 생각하면 될 것 같다.


내가 했던것을 예를들면 


x = self.conv1(x)

x = self.dropout(x)

x = self.pool(F.relu(x))

x = self.conv2(x)


... 

뭐 이런식으로 썼다. 


하지만 위의 함수를 쓰면 


model = nn.Sequential(

nn.Conv2d(....),

nn.ReLU(),

nn.Conv2d(20,64,5),

nn.RELU()

)


이므로 forward() 에서 


x = self.model(x) 만 써주면 된다.


깔끔하고 편리한 함수인것 같다.


이걸 왜 지금 알았을까 


원문보러가기

반응형

'AI > Pytorch api' 카테고리의 다른 글

[Pytorch]torch.nn.functoinal.pad()  (2) 2020.12.29
[Pytorch] torch.Tensor.view  (0) 2018.05.23
[Pytorch] torch.nn.Upsample  (0) 2018.04.01
[Pytorch] torch.nn.Conv2d  (0) 2018.04.01
Comments