| save_model | R Documentation |
.keras file.Saves a model as a .keras file.
save_model(model, filepath = NULL, overwrite = FALSE, zipped = NULL, ...)
model |
A keras model. |
filepath |
string,
Path where to save the model. Must end in |
overwrite |
Whether we should overwrite any existing model at the target location, or instead ask the user via an interactive prompt. |
zipped |
Whether to save the model as a zipped |
... |
For forward/backward compatability. |
If filepath is provided, then this function is called primarily
for side effects, and model is returned invisibly. If filepath is not
provided or NULL, then the serialized model is returned as an R raw
vector.
model <- keras_model_sequential(input_shape = c(3)) |>
layer_dense(5) |>
layer_activation_softmax()
model |> save_model("model.keras")
loaded_model <- load_model("model.keras")
x <- random_uniform(c(10, 3)) stopifnot(all.equal( model |> predict(x), loaded_model |> predict(x) ))
The saved .keras file is a zip archive that contains:
The model's configuration (architecture)
The model's weights
The model's optimizer's state (if any)
Thus models can be reinstantiated in the exact same state.
zip::zip_list("model.keras")[, "filename"]
## [1] "metadata.json" "config.json" "model.weights.h5"
load_model()
Other saving and loading functions:
export_savedmodel.keras.src.models.model.Model()
layer_tfsm()
load_model()
load_model_weights()
register_keras_serializable()
save_model_config()
save_model_weights()
with_custom_object_scope()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.