本文整理汇总了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
示例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))
示例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')
示例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
示例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