기타/etc

[Pytorch] Summary 사용하기

파송송 2021. 11. 12. 18:36
728x90

Module

from torchsummary import summary

모델 구조

class CNN(nn.Module):
    def __init__(self):
        super(CNN, self).__init__()
        self.conv1 = nn.Conv2d(1, 32, 3, 1)
        self.conv2 = nn.Conv2d(32, 64, 3, 1)
        self.dropout1 = nn.Dropout2d(0.25)
        self.dropout2 = nn.Dropout2d(0.5)
        self.fc1 = nn.Linear(9216, 128)
        self.fc2 = nn.Linear(128, 10)

    def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = self.conv2(x)
        x = F.relu(x)
        x = F.max_pool2d(x, 2)
        x = self.dropout1(x)
        x = torch.flatten(x, 1)
        x = self.fc1(x)
        x = F.relu(x)
        x = self.dropout2(x)
        x = self.fc2(x)
        output = F.log_softmax(x, dim=1)

        return output

summary 확인

model = CNN().to(device)
print(model)
print(summary(model,(1,28,28)))

summary(model,(Channels, Width, Height))

결과

forward를 forword로 적고 raise NotImplementedError 가 계속 발생했다.

들여쓰기를 잘못해도 위와 같은 오류가 뜬다고 하니 모두 조심하자..!

728x90