當前位置: 首頁>>代碼示例>>Python>>正文


Python signature_constants.CLASSIFY_METHOD_NAME屬性代碼示例

本文整理匯總了Python中tensorflow.python.saved_model.signature_constants.CLASSIFY_METHOD_NAME屬性的典型用法代碼示例。如果您正苦於以下問題:Python signature_constants.CLASSIFY_METHOD_NAME屬性的具體用法?Python signature_constants.CLASSIFY_METHOD_NAME怎麽用?Python signature_constants.CLASSIFY_METHOD_NAME使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在tensorflow.python.saved_model.signature_constants的用法示例。


在下文中一共展示了signature_constants.CLASSIFY_METHOD_NAME屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: classification_signature_def

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def classification_signature_def(examples, classes, scores):
  """Creates classification signature from given examples and predictions.

  Args:
    examples: `Tensor`.
    classes: `Tensor`.
    scores: `Tensor`.

  Returns:
    A classification-flavored signature_def.

  Raises:
    ValueError: If examples is `None`.
  """
  if examples is None:
    raise ValueError('examples cannot be None for classification.')
  if classes is None and scores is None:
    raise ValueError('classes and scores cannot both be None for '
                     'classification.')

  input_tensor_info = utils.build_tensor_info(examples)
  signature_inputs = {signature_constants.CLASSIFY_INPUTS: input_tensor_info}

  signature_outputs = {}
  if classes is not None:
    classes_tensor_info = utils.build_tensor_info(classes)
    signature_outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES] = (
        classes_tensor_info)
  if scores is not None:
    scores_tensor_info = utils.build_tensor_info(scores)
    signature_outputs[signature_constants.CLASSIFY_OUTPUT_SCORES] = (
        scores_tensor_info)

  signature_def = build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.CLASSIFY_METHOD_NAME)

  return signature_def 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:40,代碼來源:signature_def_utils_impl.py

示例2: testClassificationSignatureDef

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def testClassificationSignatureDef(self):
    input1 = constant_op.constant("a", name="input-1")
    output1 = constant_op.constant("b", name="output-1")
    output2 = constant_op.constant("c", name="output-2")
    signature_def = signature_def_utils.classification_signature_def(input1,
                                                                     output1,
                                                                     output2)

    self.assertEqual(signature_constants.CLASSIFY_METHOD_NAME,
                     signature_def.method_name)

    # Check inputs in signature def.
    self.assertEqual(1, len(signature_def.inputs))
    x_tensor_info_actual = (
        signature_def.inputs[signature_constants.CLASSIFY_INPUTS])
    self.assertEqual("input-1:0", x_tensor_info_actual.name)
    self.assertEqual(types_pb2.DT_STRING, x_tensor_info_actual.dtype)
    self.assertEqual(0, len(x_tensor_info_actual.tensor_shape.dim))

    # Check outputs in signature def.
    self.assertEqual(2, len(signature_def.outputs))
    classes_tensor_info_actual = (
        signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES])
    self.assertEqual("output-1:0", classes_tensor_info_actual.name)
    self.assertEqual(types_pb2.DT_STRING, classes_tensor_info_actual.dtype)
    self.assertEqual(0, len(classes_tensor_info_actual.tensor_shape.dim))
    scores_tensor_info_actual = (
        signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_SCORES])
    self.assertEqual("output-2:0", scores_tensor_info_actual.name)
    self.assertEqual(types_pb2.DT_STRING, scores_tensor_info_actual.dtype)
    self.assertEqual(0, len(scores_tensor_info_actual.tensor_shape.dim)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:33,代碼來源:signature_def_utils_test.py

示例3: testConvertDefaultSignatureClassificationToSignatureDef

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def testConvertDefaultSignatureClassificationToSignatureDef(self):
    signatures_proto = manifest_pb2.Signatures()
    classification_signature = manifest_pb2.ClassificationSignature()
    classification_signature.input.CopyFrom(
        manifest_pb2.TensorBinding(
            tensor_name=signature_constants.CLASSIFY_INPUTS))
    classification_signature.classes.CopyFrom(
        manifest_pb2.TensorBinding(
            tensor_name=signature_constants.CLASSIFY_OUTPUT_CLASSES))
    classification_signature.scores.CopyFrom(
        manifest_pb2.TensorBinding(
            tensor_name=signature_constants.CLASSIFY_OUTPUT_SCORES))
    signatures_proto.default_signature.classification_signature.CopyFrom(
        classification_signature)

    signatures_proto.default_signature.classification_signature.CopyFrom(
        classification_signature)
    signature_def = bundle_shim._convert_default_signature_to_signature_def(
        signatures_proto)

    # Validate classification signature correctly copied over.
    self.assertEqual(signature_def.method_name,
                     signature_constants.CLASSIFY_METHOD_NAME)
    self.assertEqual(len(signature_def.inputs), 1)
    self.assertEqual(len(signature_def.outputs), 2)
    self.assertProtoEquals(
        signature_def.inputs[signature_constants.CLASSIFY_INPUTS],
        meta_graph_pb2.TensorInfo(name=signature_constants.CLASSIFY_INPUTS))
    self.assertProtoEquals(
        signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_SCORES],
        meta_graph_pb2.TensorInfo(
            name=signature_constants.CLASSIFY_OUTPUT_SCORES))
    self.assertProtoEquals(
        signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES],
        meta_graph_pb2.TensorInfo(
            name=signature_constants.CLASSIFY_OUTPUT_CLASSES)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:38,代碼來源:bundle_shim_test.py

示例4: _convert_default_signature_to_signature_def

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def _convert_default_signature_to_signature_def(signatures):
  """Convert default signature to object of type SignatureDef.

  Args:
    signatures: object of type manifest_pb2.Signatures()

  Returns:
    object of type SignatureDef which contains a converted version of default
    signature from input signatures object

  Raises:
    RuntimeError: if default signature type is not classification or regression.
  """
  default_signature = signatures.default_signature
  signature_def = meta_graph_pb2.SignatureDef()
  if default_signature.WhichOneof("type") == "regression_signature":
    regression_signature = default_signature.regression_signature
    signature_def.method_name = signature_constants.REGRESS_METHOD_NAME
    _add_input_to_signature_def(regression_signature.input.tensor_name,
                                signature_constants.REGRESS_INPUTS,
                                signature_def)
    _add_output_to_signature_def(regression_signature.output.tensor_name,
                                 signature_constants.REGRESS_OUTPUTS,
                                 signature_def)
  elif default_signature.WhichOneof("type") == "classification_signature":
    classification_signature = default_signature.classification_signature
    signature_def.method_name = signature_constants.CLASSIFY_METHOD_NAME
    _add_input_to_signature_def(classification_signature.input.tensor_name,
                                signature_constants.CLASSIFY_INPUTS,
                                signature_def)
    _add_output_to_signature_def(classification_signature.classes.tensor_name,
                                 signature_constants.CLASSIFY_OUTPUT_CLASSES,
                                 signature_def)
    _add_output_to_signature_def(classification_signature.scores.tensor_name,
                                 signature_constants.CLASSIFY_OUTPUT_SCORES,
                                 signature_def)
  else:
    raise RuntimeError("Only classification and regression default signatures "
                       "are supported for up-conversion. %s is not "
                       "supported" % default_signature.WhichOneof("type"))
  return signature_def 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:43,代碼來源:bundle_shim.py

示例5: _is_valid_classification_signature

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def _is_valid_classification_signature(signature_def):
  """Determine whether the argument is a servable 'classify' SignatureDef."""
  if signature_def.method_name != signature_constants.CLASSIFY_METHOD_NAME:
    return False

  if (set(signature_def.inputs.keys())
      != set([signature_constants.CLASSIFY_INPUTS])):
    return False
  if (signature_def.inputs[signature_constants.CLASSIFY_INPUTS].dtype !=
      types_pb2.DT_STRING):
    return False

  allowed_outputs = set([signature_constants.CLASSIFY_OUTPUT_CLASSES,
                         signature_constants.CLASSIFY_OUTPUT_SCORES])

  if not signature_def.outputs.keys():
    return False
  if set(signature_def.outputs.keys()) - allowed_outputs:
    return False
  if (signature_constants.CLASSIFY_OUTPUT_CLASSES in signature_def.outputs
      and
      signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES].dtype
      != types_pb2.DT_STRING):
    return False
  if (signature_constants.CLASSIFY_OUTPUT_SCORES in signature_def.outputs
      and
      signature_def.outputs[signature_constants.CLASSIFY_OUTPUT_SCORES].dtype !=
      types_pb2.DT_FLOAT):
    return False

  return True 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:33,代碼來源:signature_def_utils_impl.py

示例6: _convert_default_signature_to_signature_def

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def _convert_default_signature_to_signature_def(signatures):
  """Convert default signature to object of type SignatureDef.

  Args:
    signatures: object of type manifest_pb2.Signatures()

  Returns:
    object of type SignatureDef which contains a converted version of default
    signature from input signatures object

    Returns None if signature is of generic type because it cannot be converted
    to SignatureDef.

  """
  default_signature = signatures.default_signature
  signature_def = meta_graph_pb2.SignatureDef()
  if default_signature.WhichOneof("type") == "regression_signature":
    regression_signature = default_signature.regression_signature
    signature_def.method_name = signature_constants.REGRESS_METHOD_NAME
    _add_input_to_signature_def(regression_signature.input.tensor_name,
                                signature_constants.REGRESS_INPUTS,
                                signature_def)
    _add_output_to_signature_def(regression_signature.output.tensor_name,
                                 signature_constants.REGRESS_OUTPUTS,
                                 signature_def)
  elif default_signature.WhichOneof("type") == "classification_signature":
    classification_signature = default_signature.classification_signature
    signature_def.method_name = signature_constants.CLASSIFY_METHOD_NAME
    _add_input_to_signature_def(classification_signature.input.tensor_name,
                                signature_constants.CLASSIFY_INPUTS,
                                signature_def)
    _add_output_to_signature_def(classification_signature.classes.tensor_name,
                                 signature_constants.CLASSIFY_OUTPUT_CLASSES,
                                 signature_def)
    _add_output_to_signature_def(classification_signature.scores.tensor_name,
                                 signature_constants.CLASSIFY_OUTPUT_SCORES,
                                 signature_def)
  else:
    logging.error("Only classification and regression default signatures "
                  "are supported for up-conversion. %s is not "
                  "supported" % default_signature.WhichOneof("type"))
    return None
  return signature_def 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:45,代碼來源:bundle_shim.py

示例7: export

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def export(model_version, model_dir, sess, x, y_op):
    """導出tensorflow_serving可用的模型
    SavedModel(tensorflow.python.saved_model)提供了一種跨語言格式來保存和恢複訓練後的TensorFlow模型。它使用方法簽名來定義Graph的輸入和輸出,使上層係統能夠更方便地生成、調用或轉換TensorFlow模型。
    SavedModelBuilder類提供保存Graphs、Variables及Assets的方法。所保存的Graphs必須標注用途標簽。在這個實例中我們打算將模型用於服務而非訓練,因此我們用SavedModel預定義好的tag_constant.Serving標簽。
    為了方便地構建簽名,SavedModel提供了signature_def_utils API。我們通過signature_def_utils.build_signature_def()來構建predict_signature。一個predict_signature至少包含以下參數:
    * inputs  = {'x': tensor_info_x} 指定輸入的tensor信息
    * outputs = {'y': tensor_info_y} 指定輸出的tensor信息
    * method_name = signature_constants.PREDICT_METHOD_NAME
    method_name定義方法名,它的值應該是tensorflow/serving/predict、tensorflow/serving/classify和tensorflow/serving/regress三者之一。Builder標簽用來明確Meta Graph被加載的方式,隻接受serve和train兩種類型。
    """
    if model_version <= 0:
        logging.warning('Please specify a positive value for version number.')
        sys.exit()

    path = os.path.dirname(os.path.abspath(model_dir))
    if os.path.isdir(path) == False:
        logging.warning('Path (%s) not exists, making directories...', path)
        os.makedirs(path)

    export_path = os.path.join(
        compat.as_bytes(model_dir),
        compat.as_bytes(str(model_version)))

    if os.path.isdir(export_path) == True:
        logging.warning('Path (%s) exists, removing directories...', export_path)
        shutil.rmtree(export_path)

    builder = saved_model_builder.SavedModelBuilder(export_path)
    tensor_info_x = utils.build_tensor_info(x)
    tensor_info_y = utils.build_tensor_info(y_op)

    prediction_signature = signature_def_utils.build_signature_def(
        inputs={'x': tensor_info_x},
        outputs={'y': tensor_info_y},
        # signature_constants.CLASSIFY_METHOD_NAME = "tensorflow/serving/classify"
        # signature_constants.PREDICT_METHOD_NAME  = "tensorflow/serving/predict"
        # signature_constants.REGRESS_METHOD_NAME  = "tensorflow/serving/regress"
        # 如果缺失method_name會報錯:
        # grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.INTERNAL, details="Expected prediction signature method_name to be one of {tensorflow/serving/predict, tensorflow/serving/classify, tensorflow/serving/regress}. Was: ")
        method_name=signature_constants.PREDICT_METHOD_NAME)

    builder.add_meta_graph_and_variables(
        sess,
        # tag_constants.SERVING  = "serve"
        # tag_constants.TRAINING = "train"
        # 如果隻有train標簽,TensorFlow Serving加載時會報錯:
        # E tensorflow_serving/core/aspired_versions_manager.cc:351] Servable {name: default version: 2} cannot be loaded: Not found: Could not find meta graph def matching supplied tags.
        [tag_constants.SERVING],
        signature_def_map={
            'predict_text': prediction_signature,
            # 如果缺失會報錯:
            # grpc.framework.interfaces.face.face.AbortionError: AbortionError(code=StatusCode.FAILED_PRECONDITION, details="Default serving signature key not found.")
            signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: prediction_signature
        })

    builder.save() 
開發者ID:tensorlayer,項目名稱:text-antispam,代碼行數:58,代碼來源:rnn_classifier.py

示例8: classification_signature_def

# 需要導入模塊: from tensorflow.python.saved_model import signature_constants [as 別名]
# 或者: from tensorflow.python.saved_model.signature_constants import CLASSIFY_METHOD_NAME [as 別名]
def classification_signature_def(examples, classes, scores):
  """Creates classification signature from given examples and predictions.

  Args:
    examples: `Tensor`.
    classes: `Tensor`.
    scores: `Tensor`.

  Returns:
    A classification-flavored signature_def.

  Raises:
    ValueError: If examples is `None`.
  """
  if examples is None:
    raise ValueError('Classification examples cannot be None.')
  if not isinstance(examples, ops.Tensor):
    raise ValueError('Classification examples must be a string Tensor.')
  if classes is None and scores is None:
    raise ValueError('Classification classes and scores cannot both be None.')

  input_tensor_info = utils.build_tensor_info(examples)
  if input_tensor_info.dtype != types_pb2.DT_STRING:
    raise ValueError('Classification examples must be a string Tensor.')
  signature_inputs = {signature_constants.CLASSIFY_INPUTS: input_tensor_info}

  signature_outputs = {}
  if classes is not None:
    classes_tensor_info = utils.build_tensor_info(classes)
    if classes_tensor_info.dtype != types_pb2.DT_STRING:
      raise ValueError('Classification classes must be a string Tensor.')
    signature_outputs[signature_constants.CLASSIFY_OUTPUT_CLASSES] = (
        classes_tensor_info)
  if scores is not None:
    scores_tensor_info = utils.build_tensor_info(scores)
    if scores_tensor_info.dtype != types_pb2.DT_FLOAT:
      raise ValueError('Classification scores must be a float Tensor.')
    signature_outputs[signature_constants.CLASSIFY_OUTPUT_SCORES] = (
        scores_tensor_info)

  signature_def = build_signature_def(
      signature_inputs, signature_outputs,
      signature_constants.CLASSIFY_METHOD_NAME)

  return signature_def 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:47,代碼來源:signature_def_utils_impl.py


注:本文中的tensorflow.python.saved_model.signature_constants.CLASSIFY_METHOD_NAME屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。