parameters: (
        self, export_dir_base, serving_input_receiver_fn,
        assets_extra=None,
        as_text=False,
        checkpoint_path=None)
docstring: Exports inference graph as a SavedModel into given dir.
  
      This method builds a new graph by first calling the
      serving_input_receiver_fn to obtain feature `Tensor`s, 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
      `ExportOutput`s, 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'}`.
  
      Args:
        export_dir_base: A string containing a directory in which to create
          timestamped subdirectories containing exported SavedModels.
        serving_input_receiver_fn: A function that takes no argument and
          returns a `ServingInputReceiver`.
        assets_extra: A dict specifying how to populate the assets.extra directory
          within the exported SavedModel, or `None` 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 `None` (the default),
          the most recent checkpoint found within the model directory is chosen.
  
      Returns:
        The string path to the exported directory.
  
      Raises:
        ValueError: if no serving_input_receiver_fn is provided, no export_outputs
            are provided, or no checkpoint can be found.
docstring_summary: Exports inference graph as a SavedModel into given dir.
docstring_tokens: Exports inference graph as a SavedModel into given dir .
function: def export_savedmodel(
        self, export_dir_base, serving_input_receiver_fn,
        assets_extra=None,
        as_text=False,
        checkpoint_path=None):
      """Exports inference graph as a SavedModel into given dir.
  
      This method builds a new graph by first calling the
      serving_input_receiver_fn to obtain feature `Tensor`s, 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
      `ExportOutput`s, 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'}`.
  
      Args:
        export_dir_base: A string containing a directory in which to create
          timestamped subdirectories containing exported SavedModels.
        serving_input_receiver_fn: A function that takes no argument and
          returns a `ServingInputReceiver`.
        assets_extra: A dict specifying how to populate the assets.extra directory
          within the exported SavedModel, or `None` 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 `None` (the default),
          the most recent checkpoint found within the model directory is chosen.
  
      Returns:
        The string path to the exported directory.
  
      Raises:
        ValueError: if no serving_input_receiver_fn is provided, no export_outputs
            are provided, or no checkpoint can be found.
      """
      if serving_input_receiver_fn is None:
        raise ValueError('serving_input_receiver_fn must be defined.')
  
      with ops.Graph().as_default() as g:
        self._create_and_assert_global_step(g)
        random_seed.set_random_seed(self._config.tf_random_seed)
        serving_input_receiver = serving_input_receiver_fn()
  
        # Call the model_fn and collect the export_outputs.
        estimator_spec = self._call_model_fn(
            features=serving_input_receiver.features,
            labels=None,
            mode=model_fn_lib.ModeKeys.PREDICT)
  
        # Build the SignatureDefs from receivers and all outputs
        signature_def_map = build_all_signature_defs(
            serving_input_receiver.receiver_tensors,
            estimator_spec.export_outputs)
  
        if not checkpoint_path:
          # Locate the latest checkpoint
          checkpoint_path = saver.latest_checkpoint(self._model_dir)
        if not checkpoint_path:
          raise ValueError("Couldn't find trained model at %s." % self._model_dir)
  
        export_dir = get_timestamped_export_dir(export_dir_base)
  
        # TODO(soergel): Consider whether MonitoredSession makes sense here
        with tf_session.Session() as session:
  
          saver_for_restore = estimator_spec.scaffold.saver or saver.Saver(
              sharded=True)
          saver_for_restore.restore(session, checkpoint_path)
  
          # TODO(b/36111876): replace legacy_init_op with main_op mechanism
          # pylint: disable=protected-access
          local_init_op = (
              estimator_spec.scaffold.local_init_op or
              monitored_session.Scaffold._default_local_init_op())
          # pylint: enable=protected-access
  
          # Perform the export
          builder = saved_model_builder.SavedModelBuilder(export_dir)
          builder.add_meta_graph_and_variables(
              session, [tag_constants.SERVING],
              signature_def_map=signature_def_map,
              assets_collection=ops.get_collection(
                  ops.GraphKeys.ASSET_FILEPATHS),
              legacy_init_op=local_init_op)
          builder.save(as_text)
  
        # Add the extra assets
        if assets_extra:
          assets_extra_path = os.path.join(compat.as_bytes(export_dir),
                                           compat.as_bytes('assets.extra'))
          for dest_relative, source in assets_extra.items():
            dest_absolute = os.path.join(compat.as_bytes(assets_extra_path),
                                         compat.as_bytes(dest_relative))
            dest_path = os.path.dirname(dest_absolute)
            gfile.MakeDirs(dest_path)
            gfile.Copy(source, dest_absolute)
  
        return export_dir
function_tokens: def export_savedmodel ( self , export_dir_base , serving_input_receiver_fn , assets_extra = None , as_text = False , checkpoint_path = None ) : if serving_input_receiver_fn is None : raise ValueError ( 'serving_input_receiver_fn must be defined.' ) with ops . Graph ( ) . as_default ( ) as g : self . _create_and_assert_global_step ( g ) random_seed . set_random_seed ( self . _config . tf_random_seed ) serving_input_receiver = serving_input_receiver_fn ( ) # Call the model_fn and collect the export_outputs. estimator_spec = self . _call_model_fn ( features = serving_input_receiver . features , labels = None , mode = model_fn_lib . ModeKeys . PREDICT ) # Build the SignatureDefs from receivers and all outputs signature_def_map = build_all_signature_defs ( serving_input_receiver . receiver_tensors , estimator_spec . export_outputs ) if not checkpoint_path : # Locate the latest checkpoint checkpoint_path = saver . latest_checkpoint ( self . _model_dir ) if not checkpoint_path : raise ValueError ( "Couldn't find trained model at %s." % self . _model_dir ) export_dir = get_timestamped_export_dir ( export_dir_base ) # TODO(soergel): Consider whether MonitoredSession makes sense here with tf_session . Session ( ) as session : saver_for_restore = estimator_spec . scaffold . saver or saver . Saver ( sharded = True ) saver_for_restore . restore ( session , checkpoint_path ) # TODO(b/36111876): replace legacy_init_op with main_op mechanism # pylint: disable=protected-access local_init_op = ( estimator_spec . scaffold . local_init_op or monitored_session . Scaffold . _default_local_init_op ( ) ) # pylint: enable=protected-access # Perform the export builder = saved_model_builder . SavedModelBuilder ( export_dir ) builder . add_meta_graph_and_variables ( session , [ tag_constants . SERVING ] , signature_def_map = signature_def_map , assets_collection = ops . get_collection ( ops . GraphKeys . ASSET_FILEPATHS ) , legacy_init_op = local_init_op ) builder . save ( as_text ) # Add the extra assets if assets_extra : assets_extra_path = os . path . join ( compat . as_bytes ( export_dir ) , compat . as_bytes ( 'assets.extra' ) ) for dest_relative , source in assets_extra . items ( ) : dest_absolute = os . path . join ( compat . as_bytes ( assets_extra_path ) , compat . as_bytes ( dest_relative ) ) dest_path = os . path . dirname ( dest_absolute ) gfile . MakeDirs ( dest_path ) gfile . Copy ( source , dest_absolute ) return export_dir