Issue
I am trying to build and train a network in python using pytorch . My forward method takes two inputs as follows :
def forward(self, x1, x2):
I trained this model in python and saved using torch.jit.script
.
Then I load this model in c++ using the torch::jit::load
.
How do I now pass the inputs to the model in c++ ?
If I try passing two separate tensors to the forward method like the following
std::vector<torch::jit::IValue> inputs1{tensor1};
std::vector<torch::jit::IValue> inputs2{tensor2};
at::Tensor output = module.forward(inputs1,inputs2).toTensor();
then I receive an error saying that the method forward expects 1 argument, 2 provided.
I can't also concatenate the two tensors since the shapes are different in all axis.
Solution
The problem is by concatenating the two tensors and giving the concatenated tensor as input to the model. Then in the forward method, we can create two separate tensors using the concatenated tensor and use them separately for the output computation.
For concatenation to work, I appended the tensors with 0's so that they are of the same size in all axis except the one in which concatenation is to be done.
Answered By - Learner
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.