Learn R Programming

ggmlR (version 0.8.1)

ag_load_model: Load an autograd module from a saved state

Description

Reconstructs an ag_* module saved with ag_save_model. The architecture is rebuilt by calling model_fn (either the one passed here, or the one stored inside the container at save time), and the saved parameter and buffer values are copied back by name.

Usage

ag_load_model(path, model_fn = NULL, device = NULL)

Value

The reconstructed module with restored weights, in eval mode.

Arguments

path

File path written by ag_save_model.

model_fn

Optional zero-argument rebuild function. Required if no model_fn was stored at save time. If both are present, this argument takes precedence.

device

Optional device for the rebuilt module ("cpu" or "gpu"). If NULL (default), the current ag_device() is used by the rebuild.

See Also

ag_save_model

Examples

Run this code
# \donttest{
build <- function() ag_sequential(ag_linear(4L, 8L), ag_linear(8L, 3L))
f <- tempfile(fileext = ".rds")
ag_save_model(build(), f, model_fn = build)
model <- ag_load_model(f)
# }

Run the code above in your browser using DataLab