(config, sess, inputs: dict, outputs: dict)
Save model to tensorflow SavedModel.
Save model to tensorflow SavedModel.
Save model to tensorflow SavedModel .
def to_saved_model(config, sess, inputs: dict, outputs: dict):
  """Save model to tensorflow SavedModel."""
  export_path_base = config["solver"]["service"]["model_path"]
  model_version = config["solver"]["service"]["model_version"]
  export_path = os.path.join(
      tf.compat.as_bytes(export_path_base), tf.compat.as_bytes(model_version))
  export_path = os.path.abspath(export_path)
  logging.info('Exporting model to: {}'.format(export_path))
  if os.path.exists(export_path):
    files = [
        one.decode()
        for one in os.listdir(export_path)
        if isinstance(one, bytes)
    ]
    if "variables" in files:
      cmd = input(
          f"Export directory already exists, and isn't empty. Overwrite? [y/n]"
      ).strip().lower()
      if cmd == "" or cmd == "y":
        shutil.rmtree(export_path)
  builder = tf.saved_model.builder.SavedModelBuilder(export_path)
  # Build the signature_def_map.
  signature_def = tf.saved_model.predict_signature_def(inputs, outputs)
  builder.add_meta_graph_and_variables(
      sess, [tf.saved_model.tag_constants.SERVING],
      signature_def_map={'infer': signature_def},
      strip_default_attrs=True)
  builder.save(as_text=True)
  logging.info('Done exporting!')
def to_saved_model ( config , sess , inputs : dict , outputs : dict ) : export_path_base = config [ "solver" ] [ "service" ] [ "model_path" ] model_version = config [ "solver" ] [ "service" ] [ "model_version" ] export_path = os . path . join ( tf . compat . as_bytes ( export_path_base ) , tf . compat . as_bytes ( model_version ) ) export_path = os . path . abspath ( export_path ) logging . info ( 'Exporting model to: {}' . format ( export_path ) ) if os . path . exists ( export_path ) : files = [ one . decode ( ) for one in os . listdir ( export_path ) if isinstance ( one , bytes ) ] if "variables" in files : cmd = input ( f"Export directory already exists, and isn't empty. Overwrite? [y/n]" ) . strip ( ) . lower ( ) if cmd == "" or cmd == "y" : shutil . rmtree ( export_path ) builder = tf . saved_model . builder . SavedModelBuilder ( export_path ) # Build the signature_def_map. signature_def = tf . saved_model . predict_signature_def ( inputs , outputs ) builder . add_meta_graph_and_variables ( sess , [ tf . saved_model . tag_constants . SERVING ] , signature_def_map = { 'infer' : signature_def } , strip_default_attrs = True ) builder . save ( as_text = True ) logging . info ( 'Done exporting!' )