DeepLearning
Restore
restore model or session from file
Save
save model or session to file
Calling Sequence
Parameters
Options
Description
Details
Examples
Compatibility
Restore(path)
Save(path,opts)
Save(path,model,opts)
path
-
string; path to saved state
model
Model object
opts
(optional) equations of the form format=name
format=one of auto, checkpoint, checkpoint[legacy], hdf5, json, or savedmodel
Specifies the file format to use when saving. Note that all formats other than checkpoint[legacy] require that a Model object be supplied as an argument to Save.
checkpoint is a TensorFlow training checkpoint file. Currently this is identical to checkpoint[legacy] but a future version may support TensorFlow version 2 checkpoint files.
checkpoint[legacy] is a TensorFlow version 1 checkpoint file.
hd5 is an HDF5 (Hierarchical Data Format) file.
json is a JSON file.
savedmodel is a TensorFlow Keras SavedModel file.
The default is auto, which attempts to infer the desired format from path and which falls back to savedmodel if no other format can be inferred.
Restore(path) command loads a saved Model or computation session to memory from a file or directory located at path. If path corresponds to a Model, a corresponding Model object is returned. If path corresponds to a session, its state is copied into the current session.
Save(path) command saves a Model or computation session in memory to a file or directory located at path.
These functions are part of the DeepLearning package, so they can be used in the short form Restore(..) and Save(..) only after executing the command with(DeepLearning). However, they can always be accessed through the long form of the command by using DeepLearning[Restore](..) or DeepLearning[Save](..).
For more information about saving models, see the TensorFlow Python API documentation for saved models.
with⁡DeepLearning:
Build a model and then save it to a directory in the SavedModel format.
data≔Import⁡datasets/pima-epidemiology-diabetes.csv,base=datadir1..600,..
model≔Sequential⁡DenseLayer⁡12,activation=relu,DenseLayer⁡8,activation=relu,DenseLayer⁡1,activation=sigmoid
model≔DeepLearning Model<keras.src.engine.sequential.Sequential object at 0x7f82af1ed8d0>
model:-Compile⁡loss=binary_crossentropy,optimizer=adam,metrics=accuracy
model:-Fit⁡data..,1..8,dataOutcome,epochs=150,batchsize=10:
Save⁡/tmp/mymodel,model
Save the previous model to a file in HDF5 format and restore from it.
Save⁡/tmp/mymodel.h5,model
Restore⁡/tmp/mymodel.h5
Save the previous model to a file in JSON format and restore from it.
Save⁡/tmp/mymodel.json,model
Restore⁡/tmp/mymodel.json
Save and restore a session in the legacy checkpoint (TensorFlow version 1) format.
SetEagerExecution⁡false
v≔Variable⁡1.0,0.5,datatype=float8
c≔Constant⁡1.5,3.0,datatype=float8
AssignAdd⁡v,c
sess≔GetDefaultSession⁡
sess:-Run⁡VariablesInitializer⁡
Save⁡/tmp/mySession.ckpt,format=checkpointlegacy
Restore⁡/tmp/mySession.ckpt,format=checkpointlegacy
The DeepLearning[Restore] and DeepLearning[Save] commands were introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
See Also
DeepLearning Overview
Download Help Document