I have a model that excepts an input of shape [1, 1, 1000]. I am creating a real-time application in which I would like to feed in a buffer (of type double*) into the model, and then write the output back into the buffer. I am having trouble with the double* to torch::Tensor conversion and back.
double* input; // written to by some other function
int len = 1000;
torch::jit::script::Module model; // loaded in from torchscript
/*
Now how do I convert input into a tensor of shape [1, 1, len],
pass it through the model, and convert it back into an array of
type double*
*/
// EDIT: figured out conversion to tensor
std::vector<torch::jit::IValue> input_tensors;
input_tensors.push_back(torch::from_blob(input, {1, 1, len}, torch::kFloat64));
torch::Tensor output_tensor = model.forward(input_tensors).toTensor();
// now how do copy back into double*
I think you can use torch::from_blob.
Take a look at the comment in this old issue
‘https://github.com/pytorch/pytorch/issues/37201’
You need to specify torch::kFloat64 as the input type in torch::from_blob in your case.