Template Function torch::save(const std::vector<torch::Tensor>&, SaveToArgs&&…)#
Defined in File serialize.h
Function Documentation#
-
template<typename ...SaveToArgs>
void torch::save(const std::vector<torch::Tensor> &tensor_vec, SaveToArgs&&... args)# Serializes the given
tensor_vecof typestd::vector<torch::Tensor>.To perform the serialization, a
serialize::OutputArchiveis constructed, and all arguments after thetensor_vecare forwarded to itssave_tomethod. For example, you can pass a filename, or anostream.std::vector<torch::Tensor> tensor_vec = { torch::randn({1, 2}), torch::randn({3, 4}) }; torch::save(tensor_vec, "my_tensor_vec.pt"); std::vector<torch::Tensor> tensor_vec = { torch::randn({5, 6}), torch::randn({7, 8}) }; std::ostringstream stream; // Note that the same stream cannot be used in multiple torch::save(...) // invocations, otherwise the header will be corrupted. torch::save(tensor_vec, stream);