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


Python meta_graph_pb2.SignatureDef方法代码示例

本文整理汇总了Python中tensorflow.core.protobuf.meta_graph_pb2.SignatureDef方法的典型用法代码示例。如果您正苦于以下问题:Python meta_graph_pb2.SignatureDef方法的具体用法?Python meta_graph_pb2.SignatureDef怎么用?Python meta_graph_pb2.SignatureDef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.core.protobuf.meta_graph_pb2的用法示例。


在下文中一共展示了meta_graph_pb2.SignatureDef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_signature_def

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def build_signature_def(inputs=None, outputs=None, method_name=None):
  """Utility function to build a SignatureDef protocol buffer.

  Args:
    inputs: Inputs of the SignatureDef defined as a proto map of string to
        tensor info.
    outputs: Outputs of the SignatureDef defined as a proto map of string to
        tensor info.
    method_name: Method name of the SignatureDef as a string.

  Returns:
    A SignatureDef protocol buffer constructed based on the supplied arguments.
  """
  signature_def = meta_graph_pb2.SignatureDef()
  if inputs is not None:
    for item in inputs:
      signature_def.inputs[item].CopyFrom(inputs[item])
  if outputs is not None:
    for item in outputs:
      signature_def.outputs[item].CopyFrom(outputs[item])
  if method_name is not None:
    signature_def.method_name = method_name
  return signature_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:25,代码来源:signature_def_utils_impl.py

示例2: _build_signature_def

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _build_signature_def(graph: tf.Graph,
                         input_nodes: list,
                         output_nodes: list) -> SignatureDef:
    """Build model signature (input- and output descriptions) for a graph"""
    signature_def = SignatureDef()

    def add_tensor(nodes, info):
        nodes[info.name].name = info.name
        if info.dtype is not None:
            dtype = dtypes.as_dtype(info.dtype)
            shape = tf.TensorShape(info.shape)
            nodes[info.name].dtype = dtype.as_datatype_enum
            nodes[info.name].tensor_shape.CopyFrom(shape.as_proto())

    for input_info in input_nodes:
        op = graph.get_operation_by_name(input_info.name)
        if op.type != c.TFJS_NODE_CONST_KEY:
            add_tensor(signature_def.inputs, input_info)
    for output_info in output_nodes:
        add_tensor(signature_def.outputs, output_info)
    return signature_def 
开发者ID:patlevin,项目名称:tfjs-to-tf,代码行数:23,代码来源:optimization.py

示例3: _is_valid_regression_signature

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _is_valid_regression_signature(signature_def):
  """Determine whether the argument is a servable 'regress' SignatureDef."""
  if signature_def.method_name != signature_constants.REGRESS_METHOD_NAME:
    return False

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

  if (set(signature_def.outputs.keys())
      != set([signature_constants.REGRESS_OUTPUTS])):
    return False
  if (signature_def.outputs[signature_constants.REGRESS_OUTPUTS].dtype !=
      types_pb2.DT_FLOAT):
    return False

  return True 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:22,代码来源:signature_def_utils_impl.py

示例4: _add_input_to_signature_def

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _add_input_to_signature_def(tensor_name, map_key, signature_def):
  """Add input tensor to signature_def.

  Args:
    tensor_name: string name of tensor to add to signature_def inputs
    map_key: string key to key into signature_def inputs map
    signature_def: object of type  meta_graph_pb2.SignatureDef()

  Sideffect:
    adds a TensorInfo with tensor_name to signature_def inputs map keyed with
    map_key
  """
  tensor_info = meta_graph_pb2.TensorInfo(name=tensor_name)
  signature_def.inputs[map_key].CopyFrom(tensor_info) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:16,代码来源:bundle_shim.py

示例5: _add_output_to_signature_def

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _add_output_to_signature_def(tensor_name, map_key, signature_def):
  """Add output tensor to signature_def.

  Args:
    tensor_name: string name of tensor to add to signature_def outputs
    map_key: string key to key into signature_def outputs map
    signature_def: object of type  meta_graph_pb2.SignatureDef()

  Sideffect:
    adds a TensorInfo with tensor_name to signature_def outputs map keyed with
    map_key
  """

  tensor_info = meta_graph_pb2.TensorInfo(name=tensor_name)
  signature_def.outputs[map_key].CopyFrom(tensor_info) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:17,代码来源:bundle_shim.py

示例6: _convert_named_signatures_to_signature_def

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _convert_named_signatures_to_signature_def(signatures):
  """Convert named signatures to object of type SignatureDef.

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

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

  Raises:
    RuntimeError: if input and output named signatures are not of type
    GenericSignature
  """
  signature_def = meta_graph_pb2.SignatureDef()
  input_signature = signatures.named_signatures[
      signature_constants.PREDICT_INPUTS]
  output_signature = signatures.named_signatures[
      signature_constants.PREDICT_OUTPUTS]
  # TODO(pdudnik): what if there are other signatures? Mimic cr/140900781 once
  # it is submitted.
  if (input_signature.WhichOneof("type") != "generic_signature" or
      output_signature.WhichOneof("type") != "generic_signature"):
    raise RuntimeError("Named input and output signatures can only be "
                       "up-converted if they are generic signature. "
                       "Input signature type is %s, output signature type is "
                       "%s" % (input_signature.WhichOneof("type"),
                               output_signature.WhichOneof("type")))

  signature_def.method_name = signature_constants.PREDICT_METHOD_NAME
  for key, val in input_signature.generic_signature.map.items():
    _add_input_to_signature_def(val.tensor_name, key, signature_def)
  for key, val in output_signature.generic_signature.map.items():
    _add_output_to_signature_def(val.tensor_name, key, signature_def)
  return signature_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:37,代码来源:bundle_shim.py

示例7: _convert_signatures_to_signature_defs

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _convert_signatures_to_signature_defs(metagraph_def):
  """Produce default and named upconverted SignatureDef objects from Signatures.

  Args:
    metagraph_def: object of type meta_graph_pb2.MetaGraphDef containing legacy
    format Session Bundle signatures

  Returns:
    default_signature_def: object of type SignatureDef which contains an
        upconverted version of default signatures in metagraph_def
    named_signature_def: object of type SignatureDef which contains an
        upconverted version of named signatures in metagraph_def
  """

  collection_def = metagraph_def.collection_def
  signatures_proto = manifest_pb2.Signatures()
  signatures = collection_def[legacy_constants.SIGNATURES_KEY].any_list.value[0]
  signatures.Unpack(signatures_proto)

  default_signature_def = None
  named_signature_def = None
  if signatures_proto.HasField("default_signature"):
    default_signature_def = _convert_default_signature_to_signature_def(
        signatures_proto)
  if len(signatures_proto.named_signatures) > 1:
    named_signature_def = _convert_named_signatures_to_signature_def(
        signatures_proto)
  return default_signature_def, named_signature_def 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:30,代码来源:bundle_shim.py

示例8: build_tensor_info

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def build_tensor_info(name=None, dtype=None, shape=None):
  """Utility function to build TensorInfo proto.

  Args:
    name: Name of the tensor to be used in the TensorInfo.
    dtype: Datatype to be set in the TensorInfo.
    shape: TensorShapeProto to specify the shape of the tensor in the
        TensorInfo.

  Returns:
    A TensorInfo protocol buffer constructed based on the supplied arguments.
  """
  return meta_graph_pb2.TensorInfo(name=name, dtype=dtype, shape=shape)

# SignatureDef helpers. 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:17,代码来源:utils.py

示例9: _mark_outputs_as_train_op

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _mark_outputs_as_train_op(graph: tf.Graph,
                              signature_def: SignatureDef) -> None:
    """Mark output nodes as training ops, so the optimizer ignores them"""
    train_op = GraphKeys.TRAIN_OP
    for _, tensor in signature_def.outputs.items():
        name = _to_node_name(tensor.name)
        graph.add_to_collection(train_op, graph.get_operation_by_name(name)) 
开发者ID:patlevin,项目名称:tfjs-to-tf,代码行数:9,代码来源:optimization.py

示例10: _run_tf_optimizer

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _run_tf_optimizer(config: ConfigProto,
                      graph: tf.Graph,
                      signature_def: SignatureDef) -> GraphDef:
    """Run the TF optimizer ("grappler") on a graph"""
    graph_def = graph.as_graph_def()
    meta_graph = export_meta_graph(graph_def=graph_def, graph=graph)
    meta_graph.signature_def['not_used_key'].CopyFrom(signature_def)
    return tf_optimizer.OptimizeGraph(config, meta_graph) 
开发者ID:patlevin,项目名称:tfjs-to-tf,代码行数:10,代码来源:optimization.py

示例11: is_valid_signature

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def is_valid_signature(signature_def):
  """Determine whether a SignatureDef can be served by TensorFlow Serving."""
  if signature_def is None:
    return False
  return (_is_valid_classification_signature(signature_def) or
          _is_valid_regression_signature(signature_def) or
          _is_valid_predict_signature(signature_def)) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:9,代码来源:signature_def_utils_impl.py

示例12: _is_valid_predict_signature

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def _is_valid_predict_signature(signature_def):
  """Determine whether the argument is a servable 'predict' SignatureDef."""
  if signature_def.method_name != signature_constants.PREDICT_METHOD_NAME:
    return False
  if not signature_def.inputs.keys():
    return False
  if not signature_def.outputs.keys():
    return False
  return True 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:11,代码来源:signature_def_utils_impl.py

示例13: _is_valid_classification_signature

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [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

示例14: get_signature_def_input_types

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def get_signature_def_input_types(signature):
  """Returns map of output names to their types.

  Args:
    signature: SignatureDef proto.

  Returns:
    Map from string to DType objects.
  """
  return _get_types_from_tensor_info_dict(signature.inputs) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:12,代码来源:signature_def_utils_impl.py

示例15: get_signature_def_output_shapes

# 需要导入模块: from tensorflow.core.protobuf import meta_graph_pb2 [as 别名]
# 或者: from tensorflow.core.protobuf.meta_graph_pb2 import SignatureDef [as 别名]
def get_signature_def_output_shapes(signature):
  """Returns map of output names to their shapes.

  Args:
    signature: SignatureDef proto.

  Returns:
    Map from string to TensorShape objects.
  """
  return _get_shapes_from_tensor_info_dict(signature.outputs) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:12,代码来源:signature_def_utils_impl.py


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