From 6af23499e7a3cf3290f73b49e96a0a94f931cd82 Mon Sep 17 00:00:00 2001 From: Cengguang Zhang Date: Tue, 16 Aug 2022 15:23:30 +0800 Subject: [PATCH] Docs: add save and load model docs. (#5397) * docs: add save and load model docs. * fix: update code style. * fix: update code style. * fix: fix typo and modify wording. * docs: add save model example to notebook. * fix: fix typo. --- .../QuickStart/orca-tf2keras-quickstart.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md b/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md index 3c287ba8..4ec2da05 100644 --- a/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md +++ b/docs/readthedocs/source/doc/Orca/QuickStart/orca-tf2keras-quickstart.md @@ -118,6 +118,34 @@ est.shutdown() print(stats) ``` +### **Step5: Save and Load the Model** + +Orca TF2 Estimator supports two formats to save and load the entire model (**TensorFlow SavedModel and Keras H5 Format**). The recommended format is SavedModel, which is the default format when you use `estimator.save()`. + +You could also save the model to Keras H5 format by passing `save_format='h5'` or a filename that ends in `.h5` or `.keras` to `estimator.save()`. + +**Note that if you run on Apache Hadoop/YARN cluster, you are recommended to save the model to HDFS and load from HDFS as well.** + +**1. SavedModel Format** + +```python +# save model in SavedModel format +estimator.save("/tmp/cifar10_model") + +# load model +estimator.load("/tmp/cifar10_model") +``` + +**2. HDF5 format** + +```python +# save model in H5 format +estimator.save("/tmp/cifar10_model.h5", save_format='h5') + +# load model +estimator.load("/tmp/cifar10_model.h5") +``` + That's it, the same code can run seamlessly in your local laptop and to distribute K8s or Hadoop cluster. **Note:** You should call `stop_orca_context()` when your program finishes.