Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. def forward(self, x):
  2. # Set initial hidden and cell states
  3. h0 = torch.zeros(self.num_layers, self.batch_size, self.hidden_size1).to(device)
  4. c0 = torch.zeros(self.num_layers, self.batch_size, self.hidden_size1).to(device)
  5. # print(h0)
  6. # print(x.shape)
  7. # print(c0)
  8. #y = np.zeros((self.batch_size, input_size, input_size))
  9. x = x.view(self.batch_size, x.shape[1], 1)
  10. hidden = (h0, c0)
  11. # Forward propagate LSTM
  12.  
  13. #print("h0.shape and c0.shape" + str(h0.shape))
  14. #print("x.shape" + str(x.shape))
  15. out, _ = self.lstm(x, hidden) # out: tensor of shape (batch_size, seq_length, hidden_size)
  16. print("out.shape:")
  17. print(out.shape)
  18. # Decode the hidden state of the last time step
  19. #print("after lstm:" + str(out.shape))
  20. out = self.dense1(out)
  21. out = self.tanh1(out)
  22. #print("after first dense layer:" + str(out.shape))
  23. out = out.view(batch_size, x.shape[1])
  24. out = self.dense2(out)
  25. out = self.tanh2(out)
  26. #print("after second dense layer:" + str(out.shape))
  27. #print(out.view(-1).shape)
  28. out = self.dense3(out)
  29. out = out.view(batch_size)
  30. return out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement