save_as: Save and load Ruta models

View source: R/save.R

save_asR Documentation

Save and load Ruta models

Description

Functions to save a trained or untrained Ruta learner into a file and load it

Usage

save_as(
  learner,
  file = paste0(substitute(learner), ".tar.gz"),
  dir,
  compression = "gzip"
)

load_from(file)

Arguments

learner

The "ruta_autoencoder" object to be saved

file

In save, filename with extension (usually .tar.gz) where the object will be saved. In load, path to the saved model

dir

Directory where to save the file. Use "." to save in the current working directory or tempdir() to use a temporary one

compression

Type of compression to be used, for R function ⁠\link{tar}⁠

Value

save_as returns the filename where the model has been saved, load_from returns the loaded model as a "ruta_autoencoder" object

Examples


x <- as.matrix(iris[, 1:4])


if (interactive() && keras::is_keras_available()) {
  # Save a trained model
  saved_file <-
    autoencoder(2) |>
    train(x) |>
    save_as("my_model.tar.gz", dir = tempdir())

  # Load and use the model
  encoded <- load_from(saved_file) |> encode(x)
}


fdavidcl/ruta documentation built on July 5, 2023, 6:32 p.m.