May 2020
Intermediate to advanced
530 pages
17h 8m
English
The second approach is to use an object of the torch::serialize::OutputArchive type and write the parameters we want to save into it. The following code shows how to implement the SaveWeights method for our model. This method writes all the parameters and buffers that exist in our module to the archive object, and then it uses the save_to method to write them in a file:
void NetImpl::SaveWeights(const std::string& file_name) { torch::serialize::OutputArchive archive; auto parameters = named_parameters(true /*recurse*/); auto buffers = named_buffers(true /*recurse*/); for (const auto& param : parameters) { if (param.value().defined()) { archive.write(param.key(), param.value()); } } for (const auto& buffer : ...Read now
Unlock full access