Have a question? Connect with the community at the TensorFlow Forum Visit Forum

SavedModelBundle

public class SavedModelBundle

SavedModelBundle represents a model loaded from storage.

The model consists of a description of the computation (a Graph ), a Session with tensors (e.g., parameters or variables in the graph) initialized to values saved in storage, and a description of the model as a MetaGraphDef protocol buffer .

Nested Classes

class SavedModelBundle.Exporter Options for exporting a SavedModel.
class SavedModelBundle.Loader Options for loading a SavedModel.

Constants

String DEFAULT_TAG

Public Methods

Map<String, Tensor >
call (Map<String, Tensor > arguments)
Invokes the default function directly from this model.
void
close ()
Releases resources (the Graph and Session ) associated with the saved model bundle.
static SavedModelBundle.Exporter
exporter (String exportDir)
Export a saved model.
ConcreteFunction
function (String signatureKey)
Return a ConcreteFunction corresponding to the function signature.
Graph
graph ()
Returns the graph that describes the computation performed by the model.
static SavedModelBundle
load (String exportDir, String... tags)
Load a saved model from an export directory.
static SavedModelBundle.Loader
loader (String exportDir)
Load a saved model.
MetaGraphDef
metaGraphDef ()
Returns the MetaGraphDef protocol buffer associated with the saved model.
Session
session ()
Returns the Session with which to perform computation using the model.
List< Signature >
signatures ()
Return the signature of all functions available in this saved model.

Inherited Methods

Constants

public static final String DEFAULT_TAG

Constant Value: "serve"

Public Methods

public Map<String, Tensor > call (Map<String, Tensor > arguments)

Invokes the default function directly from this model.

The default function selection is done based on the first of the following conditions that is true:

  • The function is the only signature available attached to the main graph of this saved model
  • The function is mapped to the default signature name, which is "serving_default"

Caller is responsible for closing all returned Tensors.

Parameters
arguments list of input tensors, mapped by their signature name
Returns
  • list of output tensors, mapped by the signature name
Throws
IllegalArgumentException if no function can be selected by default

public void close ()

Releases resources (the Graph and Session ) associated with the saved model bundle.

public static SavedModelBundle.Exporter exporter (String exportDir)

Export a saved model.

Returns a Exporter object for setting configuration options before actually saving the model.

Parameters
exportDir the directory path containing a saved model.

public ConcreteFunction function (String signatureKey)

Return a ConcreteFunction corresponding to the function signature.

ConcreteFunction myFunction = savedModelBundle.function("mySignatureKey");
 Map<String, Tensor> outputTensorMap = myFunction.call(session, inputTensorMap);
 

Parameters
signatureKey name of the SignatureDef in the saved model.
Returns
  • object that can be used to make calls to a function
Throws
IllegalArgumentException if signatureKey is not found in this saved model.

public Graph graph ()

Returns the graph that describes the computation performed by the model.

public static SavedModelBundle load (String exportDir, String... tags)

Load a saved model from an export directory. The model that is being loaded should be created using the Saved Model API .

This method is a shorthand for:

SavedModelBundle.loader().withTags(tags).load();
 

Parameters
exportDir the directory path containing a saved model.
tags the tags identifying the specific metagraphdef to load.
Returns
  • a bundle containing the graph and associated session.

public static SavedModelBundle.Loader loader (String exportDir)

Load a saved model.

Returns a Loader object that can set configuration options before actually loading the model,

Parameters
exportDir the directory path containing a saved model.

public MetaGraphDef metaGraphDef ()

Returns the MetaGraphDef protocol buffer associated with the saved model.

public Session session ()

Returns the Session with which to perform computation using the model.

Returns
  • the initialized session

public List< Signature > signatures ()

Return the signature of all functions available in this saved model.