Hi, I wish to store/load the tensors into/from a file. How can I achieve that in C++? In Python i would use the torch.load() and torch.save(), but in C++, these functions can’t be found?
In C++, the equivalent functions are torch::load()
and torch::save()
. Example usage:
auto x = torch::randn({5, 5});
auto tempfile = c10::make_tempfile();
torch::save(x, tempfile.name);
torch::Tensor y;
torch::load(y, tempfile.name);
ASSERT_TRUE(y.defined());
ASSERT_EQ(x.sizes().vec(), y.sizes().vec());
ASSERT_TRUE(x.allclose(y));