export_savedmodel.tf_estimator: Save an Estimator

Description Usage Arguments Details Value Raises See Also

View source: R/tf_estimator.R

Description

Save an estimator (alongside its weights) to the directory export_dir_base.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## S3 method for class 'tf_estimator'
export_savedmodel(
  object,
  export_dir_base,
  serving_input_receiver_fn = NULL,
  assets_extra = NULL,
  as_text = FALSE,
  checkpoint_path = NULL,
  overwrite = TRUE,
  versioned = !overwrite,
  ...
)

Arguments

object

A TensorFlow estimator.

export_dir_base

A string containing a directory in which to export the SavedModel.

serving_input_receiver_fn

A function that takes no argument and returns a ServingInputReceiver. Required for custom models.

assets_extra

A dict specifying how to populate the assets.extra directory within the exported SavedModel, or NULL if no extra assets are needed.

as_text

whether to write the SavedModel proto in text format.

checkpoint_path

The checkpoint path to export. If NULL (the default), the most recent checkpoint found within the model directory is chosen.

overwrite

Should the export_dir directory be overwritten?

versioned

Should the model be exported under a versioned subdirectory?

...

Optional arguments passed on to the estimator's export_savedmodel() method.

Details

This method builds a new graph by first calling the serving_input_receiver_fn to obtain feature Tensors, and then calling this Estimator's model_fn to generate the model graph based on those features. It restores the given checkpoint (or, lacking that, the most recent checkpoint) into this graph in a fresh session. Finally it creates a timestamped export directory below the given export_dir_base, and writes a SavedModel into it containing a single MetaGraphDef saved from this session. The exported MetaGraphDef will provide one SignatureDef for each element of the export_outputs dict returned from the model_fn, named using the same keys. One of these keys is always signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY, indicating which signature will be served when a serving request does not specify one. For each signature, the outputs are provided by the corresponding ExportOutputs, and the inputs are always the input receivers provided by the serving_input_receiver_fn. Extra assets may be written into the SavedModel via the extra_assets argument. This should be a dict, where each key gives a destination path (including the filename) relative to the assets.extra directory. The corresponding value gives the full path of the source file to be copied. For example, the simple case of copying a single file without renaming it is specified as {'my_asset_file.txt': '/path/to/my_asset_file.txt'}.

Value

The path to the exported directory, as a string.

Raises

ValueError: if no serving_input_receiver_fn is provided, no export_outputs are provided, or no checkpoint can be found.

See Also

Other custom estimator methods: estimator_spec(), estimator(), evaluate.tf_estimator(), predict.tf_estimator(), train.tf_estimator()


tfestimators documentation built on Aug. 10, 2021, 1:06 a.m.