當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。