當前位置: 首頁>>代碼示例>>Python>>正文


Python reader.read_saved_model方法代碼示例

本文整理匯總了Python中tensorflow.contrib.saved_model.python.saved_model.reader.read_saved_model方法的典型用法代碼示例。如果您正苦於以下問題:Python reader.read_saved_model方法的具體用法?Python reader.read_saved_model怎麽用?Python reader.read_saved_model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.saved_model.python.saved_model.reader的用法示例。


在下文中一共展示了reader.read_saved_model方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_serving_meta_graph_def

# 需要導入模塊: from tensorflow.contrib.saved_model.python.saved_model import reader [as 別名]
# 或者: from tensorflow.contrib.saved_model.python.saved_model.reader import read_saved_model [as 別名]
def get_serving_meta_graph_def(savedmodel_dir):
    """Extract the SERVING MetaGraphDef from a SavedModel directory.
    Args:
      savedmodel_dir: the string path to the directory containing the .pb
        and variables for a SavedModel. This is equivalent to the subdirectory
        that is created under the directory specified by --export_dir when
        running an Official Model.
    Returns:
      MetaGraphDef that should be used for tag_constants.SERVING mode.
    Raises:
      ValueError: if a MetaGraphDef matching tag_constants.SERVING is not found.
    """
    # We only care about the serving graph def
    tag_set = set([tf.saved_model.tag_constants.SERVING])
    serving_graph_def = None
    saved_model = reader.read_saved_model(savedmodel_dir)
    for meta_graph_def in saved_model.meta_graphs:
        if set(meta_graph_def.meta_info_def.tags) == tag_set:
            serving_graph_def = meta_graph_def
    if not serving_graph_def:
        raise ValueError("No MetaGraphDef found for tag_constants.SERVING. "
                         "Please make sure the SavedModel includes a SERVING def.")

    return serving_graph_def 
開發者ID:yyht,項目名稱:BERT,代碼行數:26,代碼來源:export_frozen_model.py

示例2: get_meta_graph_def

# 需要導入模塊: from tensorflow.contrib.saved_model.python.saved_model import reader [as 別名]
# 或者: from tensorflow.contrib.saved_model.python.saved_model.reader import read_saved_model [as 別名]
def get_meta_graph_def(saved_model_dir, tag_set):
  """Utility function to read a meta_graph_def from disk.

  From `saved_model_cli.py <https://github.com/tensorflow/tensorflow/blob/8e0e8d41a3a8f2d4a6100c2ea1dc9d6c6c4ad382/tensorflow/python/tools/saved_model_cli.py#L186>`_

  DEPRECATED for TF2.0+

  Args:
    :saved_model_dir: path to saved_model.
    :tag_set: list of string tags identifying the TensorFlow graph within the saved_model.

  Returns:
    A TensorFlow meta_graph_def, or raises an Exception otherwise.
  """
  from tensorflow.contrib.saved_model.python.saved_model import reader

  saved_model = reader.read_saved_model(saved_model_dir)
  set_of_tags = set(tag_set.split(','))
  for meta_graph_def in saved_model.meta_graphs:
    if set(meta_graph_def.meta_info_def.tags) == set_of_tags:
      return meta_graph_def
  raise RuntimeError("MetaGraphDef associated with tag-set {0} could not be found in SavedModel".format(tag_set)) 
開發者ID:yahoo,項目名稱:TensorFlowOnSpark,代碼行數:24,代碼來源:pipeline.py

示例3: get_meta_graph_def

# 需要導入模塊: from tensorflow.contrib.saved_model.python.saved_model import reader [as 別名]
# 或者: from tensorflow.contrib.saved_model.python.saved_model.reader import read_saved_model [as 別名]
def get_meta_graph_def(saved_model_dir, tag_set):
  """Gets MetaGraphDef from SavedModel.

  Returns the MetaGraphDef for the given tag-set and SavedModel directory.

  Args:
    saved_model_dir: Directory containing the SavedModel to inspect or execute.
    tag_set: Group of tag(s) of the MetaGraphDef to load, in string format,
        separated by ','. For tag-set contains multiple tags, all tags must be
        passed in.

  Raises:
    RuntimeError: An error when the given tag-set does not exist in the
        SavedModel.

  Returns:
    A MetaGraphDef corresponding to the tag-set.
  """
  saved_model = reader.read_saved_model(saved_model_dir)
  set_of_tags = set(tag_set.split(','))
  for meta_graph_def in saved_model.meta_graphs:
    if set(meta_graph_def.meta_info_def.tags) == set_of_tags:
      return meta_graph_def

  raise RuntimeError('MetaGraphDef associated with tag-set ' + tag_set +
                     ' could not be found in SavedModel') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:28,代碼來源:saved_model_cli.py

示例4: RunModel

# 需要導入模塊: from tensorflow.contrib.saved_model.python.saved_model import reader [as 別名]
# 或者: from tensorflow.contrib.saved_model.python.saved_model.reader import read_saved_model [as 別名]
def RunModel(saved_model_dir, signature_def_key, tag, text, ngrams_list=None):
    saved_model = reader.read_saved_model(saved_model_dir)
    meta_graph =  None
    for meta_graph_def in saved_model.meta_graphs:
        if tag in meta_graph_def.meta_info_def.tags:
            meta_graph = meta_graph_def
            break
    if meta_graph_def is None:
        raise ValueError("Cannot find saved_model with tag" + tag)
    signature_def = signature_def_utils.get_signature_def_by_key(
        meta_graph, signature_def_key)
    text = text_utils.TokenizeText(text)
    ngrams = None
    if ngrams_list is not None:
        ngrams_list = text_utils.ParseNgramsOpts(ngrams_list)
        ngrams = text_utils.GenerateNgrams(text, ngrams_list)
    example = inputs.BuildTextExample(text, ngrams=ngrams)
    example = example.SerializeToString()
    inputs_feed_dict = {
        signature_def.inputs["inputs"].name: [example],
    }
    if signature_def_key == "proba":
        output_key = "scores"
    elif signature_def_key == "embedding":
        output_key = "outputs"
    else:
        raise ValueError("Unrecognised signature_def %s" % (signature_def_key))
    output_tensor = signature_def.outputs[output_key].name
    with tf.Session() as sess:
        loader.load(sess, [tag], saved_model_dir)
        outputs = sess.run(output_tensor,
                           feed_dict=inputs_feed_dict)
        return outputs 
開發者ID:apcode,項目名稱:tensorflow_fasttext,代碼行數:35,代碼來源:predictor.py

示例5: get_serving_meta_graph_def

# 需要導入模塊: from tensorflow.contrib.saved_model.python.saved_model import reader [as 別名]
# 或者: from tensorflow.contrib.saved_model.python.saved_model.reader import read_saved_model [as 別名]
def get_serving_meta_graph_def(savedmodel_dir):
  """Extract the SERVING MetaGraphDef from a SavedModel directory.

  Args:
    savedmodel_dir: the string path to the directory containing the .pb
      and variables for a SavedModel. This is equivalent to the subdirectory
      that is created under the directory specified by --export_dir when
      running an Official Model.

  Returns:
    MetaGraphDef that should be used for tag_constants.SERVING mode.

  Raises:
    ValueError: if a MetaGraphDef matching tag_constants.SERVING is not found.
  """
  # We only care about the serving graph def
  tag_set = set([tf.saved_model.tag_constants.SERVING])
  serving_graph_def = None
  saved_model = reader.read_saved_model(savedmodel_dir)
  for meta_graph_def in saved_model.meta_graphs:
    if set(meta_graph_def.meta_info_def.tags) == tag_set:
      serving_graph_def = meta_graph_def
  if not serving_graph_def:
    raise ValueError("No MetaGraphDef found for tag_constants.SERVING. "
                     "Please make sure the SavedModel includes a SERVING def.")

  return serving_graph_def 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:29,代碼來源:tensorrt.py


注:本文中的tensorflow.contrib.saved_model.python.saved_model.reader.read_saved_model方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。