| save_shrinkGPR | R Documentation |
save_shrinkGPR saves a fitted model object to a single .zip file,
preserving the trained model, optimizer state, and all metadata needed for
prediction and continued training via cont_model.
save_shrinkGPR(obj, file)
obj |
an object of class |
file |
a character string specifying the file path to save to. |
Internally, the model components are saved as separate files via
torch_save and bundled into a single .zip archive.
This is necessary because torch nn_module objects contain external pointers
that cannot be serialized within a nested list. The plain R components (loss history,
model internals) are saved via saveRDS.
Invisibly returns the file path.
Peter Knaus peter.knaus@wu.ac.at
load_shrinkGPR
if (torch::torch_is_installed()) {
# Fit a model and save it
sim <- simGPR()
mod <- shrinkGPR(y ~ ., data = sim$data)
tmp <- tempfile(fileext = ".zip")
save_shrinkGPR(mod, tmp)
# Load it back
mod_loaded <- load_shrinkGPR(tmp)
# Continue training
mod2 <- shrinkGPR(y ~ ., data = sim$data, cont_model = mod_loaded)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.