Import PyTorch LSTM Model into Matlab
Hey Guys,
I am currently trying to use my Pytorch LSTM in Matlab (Trained with Pytorch Lightning) but I have no idea how to use the importNetworkFromPyTorch function with an LSTM. The Structure of the model is the following:
LSTM -> Linear -> Sigmoid
The LSTM properties (https://docs.pytorch.org/docs/stable/generated/torch.nn.LSTM.html) are (num_inputs=3, nhid=5, nlayers=5) which causes the Linear layer to be (in=5, out=1).
The Training Data has the shape [BS, 600, 3] with BS being batch_size, 600 being the time series and 3 being the individual input at one timestep. The shape of the hidden state is [5, BS, 5].
So my problem is that I do not understand what input sizes I have to put into the importNetworkFromPyTorch function.
I expect it so be something like this:
net = importNetworkFromPyTorch("example/path/model.pt",PyTorchInputSizes={[NaN,3], [2, 5, NaN, 5]})
I exported the traced model by:
traced_model = torch.jit.trace(model.model.forward, (input, hidden_input))
torch.jit.save(traced_model, "model.pt")
The shape of input is [3] and of hidden_input is ([5, 1, 5], [5, 1, 5]) (one for hidden state and one for context)
Can you please tell me how to use this importNetworkFromPyTorch function.Hey Guys,
I am currently trying to use my Pytorch LSTM in Matlab (Trained with Pytorch Lightning) but I have no idea how to use the importNetworkFromPyTorch function with an LSTM. The Structure of the model is the following:
LSTM -> Linear -> Sigmoid
The LSTM properties (https://docs.pytorch.org/docs/stable/generated/torch.nn.LSTM.html) are (num_inputs=3, nhid=5, nlayers=5) which causes the Linear layer to be (in=5, out=1).
The Training Data has the shape [BS, 600, 3] with BS being batch_size, 600 being the time series and 3 being the individual input at one timestep. The shape of the hidden state is [5, BS, 5].
So my problem is that I do not understand what input sizes I have to put into the importNetworkFromPyTorch function.
I expect it so be something like this:
net = importNetworkFromPyTorch("example/path/model.pt",PyTorchInputSizes={[NaN,3], [2, 5, NaN, 5]})
I exported the traced model by:
traced_model = torch.jit.trace(model.model.forward, (input, hidden_input))
torch.jit.save(traced_model, "model.pt")
The shape of input is [3] and of hidden_input is ([5, 1, 5], [5, 1, 5]) (one for hidden state and one for context)
Can you please tell me how to use this importNetworkFromPyTorch function. Hey Guys,
I am currently trying to use my Pytorch LSTM in Matlab (Trained with Pytorch Lightning) but I have no idea how to use the importNetworkFromPyTorch function with an LSTM. The Structure of the model is the following:
LSTM -> Linear -> Sigmoid
The LSTM properties (https://docs.pytorch.org/docs/stable/generated/torch.nn.LSTM.html) are (num_inputs=3, nhid=5, nlayers=5) which causes the Linear layer to be (in=5, out=1).
The Training Data has the shape [BS, 600, 3] with BS being batch_size, 600 being the time series and 3 being the individual input at one timestep. The shape of the hidden state is [5, BS, 5].
So my problem is that I do not understand what input sizes I have to put into the importNetworkFromPyTorch function.
I expect it so be something like this:
net = importNetworkFromPyTorch("example/path/model.pt",PyTorchInputSizes={[NaN,3], [2, 5, NaN, 5]})
I exported the traced model by:
traced_model = torch.jit.trace(model.model.forward, (input, hidden_input))
torch.jit.save(traced_model, "model.pt")
The shape of input is [3] and of hidden_input is ([5, 1, 5], [5, 1, 5]) (one for hidden state and one for context)
Can you please tell me how to use this importNetworkFromPyTorch function. python, pytorch, lstm, load nn MATLAB Answers — New Questions