当前位置: 首页>>代码示例>>Python>>正文


Python exporter.classification_signature方法代码示例

本文整理汇总了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, {} 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:export.py

示例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, {} 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:classifier.py

示例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 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:head.py

示例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, {} 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:28,代码来源:export.py

示例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() 
开发者ID:vackosar,项目名称:keras-punctuator,代码行数:42,代码来源:punctuator.py


注:本文中的tensorflow.contrib.session_bundle.exporter.classification_signature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。