Taking a deep dive into saved models

You are required to export (or to save) your qualified machine learning model as one or more objects in order to perform Google Cloud AI Platform predictions. This section explains various ways to export qualified models for AI system prediction deployment. Depending upon the type of machine learning platform that you use, the Google Cloud AI Platform gives you multiple ways to export those models. These methods are specific to the framework that is used to train the model. We will cover some aspects of the TensorFlow saved model in this section. You must first export your trained models to the Google Cloud AI Platform in the format of a TensorFlow SavedModel to support the predictions.

A saved TensorFlow model actually contains a TensorFlow program with weights and computations. It does not point to the code used to build the model, but the code required to make predictions with derived mathematical parameters. As it is called the SavedModel, TensorFlow is the recommended format to deploy trained models in the Google Cloud AI Platform. It is recommended to export the TensorFlow SavedModel. 

Exporting your trained SavedModel model saves the training graph in a Google Cloud AI Platform-specific format that can be used and restored for forecasts using its metadata. SavedModel offers a language-neutral format for saving recoverable and hermetic machine-learned models. It helps systems and resources of higher levels to generate, consume, and process TensorFlow models. The following are some of the important features of a SavedModel:

  • A single SavedModel can be added to multiple graphs with a single set of variables and assets. Every diagram is connected to a set of tags for identification while loading or restoring. Graphs are stored in a protocol buffers format.
  • SavedModel has support for SignatureDef (the technical name for a protocol buffer message). SavedModel uses this to provide support for signatures that are stored with the graphs. These graphs used for machine learning prediction work typically containing a bunch of data inputs and data outputs are called Signatures. A Signature has the following structure:
  • inputs: Corresponding data inputs used to train TensorFlow models stored a map list of strings.
  • outputsCorresponding data outputs used to train TensorFlow models stored a map list of strings.
  • method_name: Supported methods named used in the TensorFlow framework.
  • SavedModel has support for assets as well. SavedModel uses assets if operations depend on external initialization files, such as vocabulary. Assets are copied to the SavedModel directory and read when a particular metagraph def is loaded.
  • It supports clear devices before the SavedModel is generated.

As the preceding section mentioned, although some of the important features are supported by SavedModels, other features are not supported. These are as follows:

  • It does not have support for implicit versioning.
  • It does not support garbage collection by itself. External tools that use these models may have support for these.
  • It does not support atomic writes to TensorFlow SavedModels.

The SavedModel directory has the following structure:

assets/
assets.extra/
variables/
variables.data-?????-of-?????
variables.index
saved_model.pb

The saved_model.pb or saved_model.pbtxt file is the protocol buffer file that includes all the graph definitions as a MetaGraphDef protocol buffer message. The assets subfolder contains supporting auxiliary files, such as text vocabulary files. The assets.extra subfolder contains user-added assets that can co-exist with the model, but this is not loaded at runtime. The user or end developer has to manage it by itself as the TensorFlow libraries do not manage it. The variables subfolder contains output from the TensorFlow library TensorFlow saver.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.152.87