Search code examples
lstmpytorchtorch

TypeError: view() takes at most 2 arguments (3 given)


I try to use view() in pytorch but i can't input 3 arguments.I don't know why it keep giving this error? Can anyone help me with this?

    def forward(self, input):
        lstm_out, self.hidden = self.lstm(input.view(len(input), self.batch_size, -1))

Solution

  • It looks like your input is a numpy array, not torch tensor. You need to convert it first, like input = torch.Tensor(input).