로그인 바로가기 하위 메뉴 바로가기 본문 바로가기
PROJECT
난이도
기본

파이토치로 시작하는 딥러닝 기초

임시 이미지 Deep Learning Zero To All
http://www.boostcourse.org/ai214/forum/112502
좋아요 635 수강생 9652

model checking하는 부분에서  아래 처럼 출력값이 (100, 1)로 나오지 않습니다.

어디가 문제일까요?


output.Torch.Size([100, 420, 1])

모델의 최종 출력의 shape...이 올바르지 않습니다. forward 함수를 정확히 구현했는지 다시 확인하시기 바랍니다.


class SimpleLSTM(nn.Module):
def __init__(self, hidden_size=100, num_layers=1):
super().__init__()
self.hidden_size = hidden_size
self.num_layers = num_layers
## 코드 시작 ##
self.lstm = nn.LSTM(input_size=9, hidden_size=self.hidden_size, num_layers=self.num_layers, batch_first=True)
self.fc = nn.Linear(self.hidden_size, 1)
## 코드 종료 ##

def init_hidden(self, batch_size):
# 코드 시작
hidden = torch.zeros(self.num_layers, batch_size, self.hidden_size) # 위의 설명 3. 을 참고하여 None을 채우세요.
cell = torch.zeros(self.num_layers, batch_size, self.hidden_size) # 위의 설명 3. 을 참고하여 None을 채우세요.
# 코드 종료
return hidden, cell

def forward(self, x):
# hidden, cell state init
h, c = self.init_hidden(x.size(0))
h, c = h.to(x.device), c.to(x.device)
## 코드 시작 ##
out, (h, c) = self.lstm(x, (h, c)) # 위의 설명 4. 를 참고하여 None을 채우세요.
final_output = self.fc(out) # 위의 설명 5. 를 참고하여 None을 채우세요.
## 코드 종료 ##
return final_output