parameters: (
        self, export_dir_base, serving_input_fn,
        default_output_alternative_key=None,
        assets_extra=None,
        as_text=False,
        checkpoint_path=None)
docstring: Exports inference graph as a SavedModel into given dir.
  
      Args:
        export_dir_base: A string containing a directory to write the exported
          graph and checkpoints.
        serving_input_fn: A function that takes no argument and
          returns an `InputFnOps`.
        default_output_alternative_key: the name of the head to serve when none is
          specified.  Not needed for single-headed models.
        assets_extra: A dict specifying how to populate the assets.extra directory
          within the exported SavedModel.  Each key should give the 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'}`.
        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 an unrecognized export_type is requested.
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_fn,
        default_output_alternative_key=None,
        assets_extra=None,
        as_text=False,
        checkpoint_path=None):
      """Exports inference graph as a SavedModel into given dir.
  
      Args:
        export_dir_base: A string containing a directory to write the exported
          graph and checkpoints.
        serving_input_fn: A function that takes no argument and
          returns an `InputFnOps`.
        default_output_alternative_key: the name of the head to serve when none is
          specified.  Not needed for single-headed models.
        assets_extra: A dict specifying how to populate the assets.extra directory
          within the exported SavedModel.  Each key should give the 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'}`.
        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 an unrecognized export_type is requested.
      """
      if serving_input_fn is None:
        raise ValueError('serving_input_fn must be defined.')
  
      with ops.Graph().as_default() as g:
        contrib_variables.create_global_step(g)
  
        # Call the serving_input_fn and collect the input alternatives.
        input_ops = serving_input_fn()
        input_alternatives, features = (
            saved_model_export_utils.get_input_alternatives(input_ops))
  
        # TODO(b/34388557) This is a stopgap, pending recording model provenance.
        # Record which features are expected at serving time.  It is assumed that
        # these are the features that were used in training.
        for feature_key in input_ops.features.keys():
          ops.add_to_collection(
              constants.COLLECTION_DEF_KEY_FOR_INPUT_FEATURE_KEYS, feature_key)
  
        # Call the model_fn and collect the output alternatives.
        model_fn_ops = self._call_model_fn(features, None,
                                           model_fn_lib.ModeKeys.INFER)
        output_alternatives, actual_default_output_alternative_key = (
            saved_model_export_utils.get_output_alternatives(
                model_fn_ops, default_output_alternative_key))
  
        # Build the SignatureDefs from all pairs of input and output alternatives
        signature_def_map = saved_model_export_utils.build_all_signature_defs(
            input_alternatives, output_alternatives,
            actual_default_output_alternative_key)
  
        if not checkpoint_path:
          # Locate the latest checkpoint
          checkpoint_path = saver.latest_checkpoint(self._model_dir)
        if not checkpoint_path:
          raise NotFittedError("Couldn't find trained model at %s."
                               % self._model_dir)
  
        export_dir = saved_model_export_utils.get_timestamped_export_dir(
            export_dir_base)
  
        if (model_fn_ops.scaffold is not None and
            model_fn_ops.scaffold.saver is not None):
          saver_for_restore = model_fn_ops.scaffold.saver
        else:
          saver_for_restore = saver.Saver(sharded=True)
        with tf_session.Session('') as session:
          saver_for_restore.restore(session, checkpoint_path)
          init_op = control_flow_ops.group(
              variables.local_variables_initializer(),
              resources.initialize_resources(resources.shared_resources()),
              lookup_ops.tables_initializer())
  
          # 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=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_fn , default_output_alternative_key = None , assets_extra = None , as_text = False , checkpoint_path = None ) : if serving_input_fn is None : raise ValueError ( 'serving_input_fn must be defined.' ) with ops . Graph ( ) . as_default ( ) as g : contrib_variables . create_global_step ( g ) # Call the serving_input_fn and collect the input alternatives. input_ops = serving_input_fn ( ) input_alternatives , features = ( saved_model_export_utils . get_input_alternatives ( input_ops ) ) # TODO(b/34388557) This is a stopgap, pending recording model provenance. # Record which features are expected at serving time.  It is assumed that # these are the features that were used in training. for feature_key in input_ops . features . keys ( ) : ops . add_to_collection ( constants . COLLECTION_DEF_KEY_FOR_INPUT_FEATURE_KEYS , feature_key ) # Call the model_fn and collect the output alternatives. model_fn_ops = self . _call_model_fn ( features , None , model_fn_lib . ModeKeys . INFER ) output_alternatives , actual_default_output_alternative_key = ( saved_model_export_utils . get_output_alternatives ( model_fn_ops , default_output_alternative_key ) ) # Build the SignatureDefs from all pairs of input and output alternatives signature_def_map = saved_model_export_utils . build_all_signature_defs ( input_alternatives , output_alternatives , actual_default_output_alternative_key ) if not checkpoint_path : # Locate the latest checkpoint checkpoint_path = saver . latest_checkpoint ( self . _model_dir ) if not checkpoint_path : raise NotFittedError ( "Couldn't find trained model at %s." % self . _model_dir ) export_dir = saved_model_export_utils . get_timestamped_export_dir ( export_dir_base ) if ( model_fn_ops . scaffold is not None and model_fn_ops . scaffold . saver is not None ) : saver_for_restore = model_fn_ops . scaffold . saver else : saver_for_restore = saver . Saver ( sharded = True ) with tf_session . Session ( '' ) as session : saver_for_restore . restore ( session , checkpoint_path ) init_op = control_flow_ops . group ( variables . local_variables_initializer ( ) , resources . initialize_resources ( resources . shared_resources ( ) ) , lookup_ops . tables_initializer ( ) ) # 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 = 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