当前位置: 首页>>代码示例>>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;未经允许,请勿转载。