Read c++ libtorch tensor into python

I am able to write a tensor to a file in c++

somefunc(at::Tensor& image) {
torch::save(image, "");

and then when I load into python and look at it’s contents it see


I get


Am I able to access the tensor from the “RecursiveScriptModule”? When I do the same thing with pytorch it just returns the original tensor. How do access the original tensor?

This should work to save a tensor in libtorch and load it in Python:

#include <torch/torch.h>
#include <iostream>

int main() {
  auto tensor = torch::ones({3, 3});
  auto bytes = torch::pickle_save(tensor);
  std::ofstream fout("", std::ios::out | std::ios::binary);
  fout.write(, bytes.size());
>>> import torch
>>> x = torch.load('')
>>> x
tensor([[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]])