本文整理汇总了Python中tensorflow.contrib.session_bundle.exporter.classification_signature方法的典型用法代码示例。如果您正苦于以下问题:Python exporter.classification_signature方法的具体用法?Python exporter.classification_signature怎么用?Python exporter.classification_signature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.session_bundle.exporter
的用法示例。
在下文中一共展示了exporter.classification_signature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classification_signature_fn
# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import classification_signature [as 别名]
def classification_signature_fn(examples, unused_features, predictions):
"""Creates classification signature from given examples and predictions.
Args:
examples: `Tensor`.
unused_features: `dict` of `Tensor`s.
predictions: `Tensor` or dict of tensors that contains the classes tensor
as in {'classes': `Tensor`}.
Returns:
Tuple of default classification signature and empty named signatures.
Raises:
ValueError: If examples is `None`.
"""
if examples is None:
raise ValueError('examples cannot be None when using this signature fn.')
if isinstance(predictions, dict):
default_signature = exporter.classification_signature(
examples, classes_tensor=predictions['classes'])
else:
default_signature = exporter.classification_signature(
examples, classes_tensor=predictions)
return default_signature, {}
示例2: classification_signature_fn
# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import classification_signature [as 别名]
def classification_signature_fn(examples, unused_features, predictions):
"""Creates classification signature from given examples and predictions.
Args:
examples: `Tensor`.
unused_features: `dict` of `Tensor`s.
predictions: `dict` of `Tensor`s.
Returns:
Tuple of default classification signature and empty named signatures.
"""
signature = exporter.classification_signature(
examples,
classes_tensor=predictions[Classifier.CLASS_OUTPUT],
scores_tensor=predictions[Classifier.PROBABILITY_OUTPUT])
return signature, {}
示例3: _create_signature_fn
# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import classification_signature [as 别名]
def _create_signature_fn(self):
"""See superclass."""
def _classification_signature_fn(examples, unused_features, predictions):
"""Servo signature function."""
if isinstance(predictions, dict):
default_signature = exporter.classification_signature(
input_tensor=examples,
classes_tensor=predictions[prediction_key.PredictionKey.CLASSES],
scores_tensor=predictions[
prediction_key.PredictionKey.PROBABILITIES])
else:
default_signature = exporter.classification_signature(
input_tensor=examples,
scores_tensor=predictions)
# TODO(zakaria): add validation
return default_signature, {}
return _classification_signature_fn
示例4: classification_signature_fn_with_prob
# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import classification_signature [as 别名]
def classification_signature_fn_with_prob(
examples, unused_features, predictions):
"""Classification signature from given examples and predicted probabilities.
Args:
examples: `Tensor`.
unused_features: `dict` of `Tensor`s.
predictions: `Tensor` of predicted probabilities or dict that contains the
probabilities tensor as in {'probabilities', `Tensor`}.
Returns:
Tuple of default classification signature and empty named signatures.
Raises:
ValueError: If examples is `None`.
"""
if examples is None:
raise ValueError('examples cannot be None when using this signature fn.')
if isinstance(predictions, dict):
default_signature = exporter.classification_signature(
examples, scores_tensor=predictions['probabilities'])
else:
default_signature = exporter.classification_signature(
examples, scores_tensor=predictions)
return default_signature, {}
示例5: saveWithSavedModel
# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import classification_signature [as 别名]
def saveWithSavedModel():
# K.set_learning_phase(0) # all new operations will be in test mode from now on
# wordIndex = loadWordIndex()
model = createModel()
model.load_weights(KERAS_WEIGHTS_FILE)
export_path = os.path.join(PUNCTUATOR_DIR, 'graph') # where to save the exported graph
shutil.rmtree(export_path, True)
export_version = 1 # version number (integer)
import tensorflow as tf
sess = tf.Session()
saver = tf.train.Saver(sharded=True)
from tensorflow.contrib.session_bundle import exporter
model_exporter = exporter.Exporter(saver)
signature = exporter.classification_signature(input_tensor=model.input,scores_tensor=model.output)
# model_exporter.init(sess.graph.as_graph_def(),default_graph_signature=signature)
tf.initialize_all_variables().run(session=sess)
# model_exporter.export(export_path, tf.constant(export_version), sess)
from tensorflow.python.saved_model import builder as saved_model_builder
builder = saved_model_builder.SavedModelBuilder(export_path)
from tensorflow.python.saved_model import signature_constants
from tensorflow.python.saved_model import tag_constants
legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def
signature_def = predict_signature_def(
{signature_constants.PREDICT_INPUTS: model.input},
{signature_constants.PREDICT_OUTPUTS: model.output})
builder.add_meta_graph_and_variables(
sess, [tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature_def
},
legacy_init_op=legacy_init_op)
builder.save()