Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

save_model_hdf5

Save/Load models using HDF5 files


Description

Save/Load models using HDF5 files

Usage

save_model_hdf5(object, filepath, overwrite = TRUE, include_optimizer = TRUE)

load_model_hdf5(filepath, custom_objects = NULL, compile = TRUE)

Arguments

object

Model object to save

filepath

File path

overwrite

Overwrite existing file if necessary

include_optimizer

If TRUE, save optimizer's state.

custom_objects

Mapping class names (or function names) of custom (non-Keras) objects to class/functions (for example, custom metrics or custom loss functions). This mapping can be done with the dict() function of reticulate.

compile

Whether to compile the model after loading.

Details

The following components of the model are saved:

  • The model architecture, allowing to re-instantiate the model.

  • The model weights.

  • The state of the optimizer, allowing to resume training exactly where you left off. This allows you to save the entirety of the state of a model in a single file.

Saved models can be reinstantiated via load_model_hdf5(). The model returned by load_model_hdf5() is a compiled model ready to be used (unless the saved model was never compiled in the first place or compile = FALSE is specified).

As an alternative to providing the custom_objects argument, you can execute the definition and persistence of your model using the with_custom_object_scope() function.

Note

The serialize_model() function enables saving Keras models to R objects that can be persisted across R sessions.

See Also


keras

R Interface to 'Keras'

v2.4.0
MIT + file LICENSE
Authors
Daniel Falbel [ctb, cph, cre], JJ Allaire [aut, cph], François Chollet [aut, cph], RStudio [ctb, cph, fnd], Google [ctb, cph, fnd], Yuan Tang [ctb, cph] (<https://orcid.org/0000-0001-5243-233X>), Wouter Van Der Bijl [ctb, cph], Martin Studer [ctb, cph], Sigrid Keydana [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.