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


Python node_def_pb2.NodeDef方法代码示例

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


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

示例1: node_from_map

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def node_from_map(node_map, name):
  """Pulls a node def from a dictionary for a given name.

  Args:
    node_map: Dictionary containing an entry indexed by name for every node.
    name: Identifies the node we want to find.

  Returns:
    NodeDef of the node with the given name.

  Raises:
    ValueError: If the node isn't present in the dictionary.
  """
  stripped_name = node_name_from_input(name)
  if stripped_name not in node_map:
    raise ValueError("No node named '%s' found in map." % name)
  return node_map[stripped_name] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:19,代码来源:optimize_for_inference_lib.py

示例2: values_from_const

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def values_from_const(node_def):
  """Extracts the values from a const NodeDef as a numpy ndarray.

  Args:
    node_def: Const NodeDef that has the values we want to access.

  Returns:
    Numpy ndarray containing the values.

  Raises:
    ValueError: If the node isn't a Const.
  """
  if node_def.op != "Const":
    raise ValueError(
        "Node named '%s' should be a Const op for values_from_const." %
        node_def.name)
  input_tensor = node_def.attr["value"].tensor
  tensor_value = tensor_util.MakeNdarray(input_tensor)
  return tensor_value 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:optimize_for_inference_lib.py

示例3: _as_node_def_input

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def _as_node_def_input(self):
    """Return a value to use for the NodeDef "input" attribute.

    The returned string can be used in a NodeDef "input" attribute
    to indicate that the NodeDef uses this Tensor as input.

    Raises:
      ValueError: if this Tensor's Operation does not have a name.

    Returns:
      a string.
    """
    if not self._op.name:
      raise ValueError("Operation was not named: %s" % self._op)
    if self._value_index == 0:
      return self._op.name
    else:
      return "%s:%d" % (self._op.name, self._value_index) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:ops.py

示例4: __init__

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def __init__(self,
               node=None,
               name=None,
               inputs=None,
               outputs=None,
               attr=None,
               domain=None,
               op_type=None):
    # storing a reference to the original protobuf object
    if node is None:
      self.node = None
      self.name = name or ""
      self.inputs = inputs or []
      self.attr = attr or {}
      self.domain = domain or ""
      self.op_type = op_type or ""
      self.outputs = outputs or self.get_outputs_names()
    elif isinstance(node, (OnnxNode, NodeProto)):
      self._load_onnx_node(node)
    elif isinstance(node, NodeDef):
      self._load_tf_node(node) 
开发者ID:onnx,项目名称:onnx-tensorflow,代码行数:23,代码来源:pb_wrapper.py

示例5: _len_node_outputs

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def _len_node_outputs(self, node_def):
        assert isinstance(node_def, node_def_pb2.NodeDef), 'node_def type %s' % type(node_def)
        op_def = self._op_defs[node_def.op]
        len_outputs = 0
        for output_argdef in op_def.output_arg:
            if output_argdef.number_attr:
                # A sequence of tensors with the same type
                len_outputs += node_def.attr[output_argdef.number_attr].i
            elif output_argdef.type_list_attr:
                # A sequence of tensors
                len_outputs += len(node_def.attr[output_argdef.type_list_attr].list.type)
            else:
                # A single tensor
                len_outputs += 1

        return len_outputs 
开发者ID:snuspl,项目名称:parallax,代码行数:18,代码来源:lib.py

示例6: extend_mapping_from_nodedef

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def extend_mapping_from_nodedef(self, single_nodedef, replica_nodedef):
        assert isinstance(single_nodedef, node_def_pb2.NodeDef), \
                'single nodedef type is %s' % type(single_nodedef)
        assert isinstance(replica_nodedef, node_def_pb2.NodeDef), \
                'replica nodedef type is %s' % type(replica_nodedef)

        def _append_mapping(tensor_or_op_name, replica_name):
            if tensor_or_op_name not in self._mapping:
                self._mapping[tensor_or_op_name] = []
            assert isinstance(self._mapping[tensor_or_op_name], list)
            self._mapping[tensor_or_op_name].append(replica_name)

        _append_mapping(single_nodedef.name, replica_nodedef.name)

        for i in range(self._len_node_outputs(single_nodedef)):
            single_tensor_name = '%s:%d' % (single_nodedef.name, i)
            replica_tensor_name = '%s:%d' % (replica_nodedef.name, i)
            _append_mapping(single_tensor_name, replica_tensor_name) 
开发者ID:snuspl,项目名称:parallax,代码行数:20,代码来源:lib.py

示例7: _local_device_setter

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def _local_device_setter(worker_device, ps_devices, ps_strategy):
  """A device setter that puts distributes Var/Ops to PS/workers."""
  ps_ops = ['Variable', 'VariableV2', 'VarHandleOp']

  def local_device_chooser(op):
    current_device = framework_device.DeviceSpec.from_string(op.device or '')

    node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
    if node_def.op in ps_ops:
      ps_device_spec = framework_device.DeviceSpec.from_string(
          '{}'.format(ps_devices[ps_strategy(op)]))

      ps_device_spec.merge_from(current_device)
      return ps_device_spec.to_string()
    else:
      worker_device_spec = framework_device.DeviceSpec.from_string(
          worker_device or '')
      worker_device_spec.merge_from(current_device)
      return worker_device_spec.to_string()

  return local_device_chooser 
开发者ID:HiKapok,项目名称:tf.fashionAI,代码行数:23,代码来源:tf_replicate_model_fn.py

示例8: get_stats_for_node_def

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def get_stats_for_node_def(graph, node, statistic_type):
  """Looks up the node's statistics function in the registry and calls it.

  This function takes a Graph object and a NodeDef from a GraphDef, and if
  there's an associated statistics method, calls it and returns a result. If no
  function has been registered for the particular node type, it returns an empty
  statistics object.

  Args:
    graph: A Graph object that's been set up with the node's graph.
    node: A NodeDef describing the operator.
    statistic_type: A string identifying the statistic we're interested in.
  Returns:
    An OpStats object containing information about resource usage.
  """

  try:
    stats_func = _stats_registry.lookup(node.op + "," + statistic_type)
    result = stats_func(graph, node)
  except LookupError:
    result = OpStats(statistic_type)
  return result 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:ops.py

示例9: build

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def build(self):
        for i, layer in enumerate(self.model.node):
            self.layer_map[layer.name] = TensorflowGraphNode(layer)
            self.layer_name_map[layer.name] = layer.name
            for pred in layer.input:
                if pred not in self.layer_map:
                    if not pred.split(':')[0] in self.layer_map: #test
                        new_node = NodeDef()
                        new_node.name = pred
                        new_node.op = "NoOp"
                        self.layer_map[pred] = TensorflowGraphNode(new_node)
                        self.layer_name_map[pred] = pred

                self.tf_make_connection(pred, layer.name)

        super(TensorflowGraph, self).build() 
开发者ID:microsoft,项目名称:MMdnn,代码行数:18,代码来源:tensorflow_graph.py

示例10: quantize_nodes_recursively

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def quantize_nodes_recursively(self, current_node):
    """The entry point for quantizing nodes to eight bit and back."""
    if self.already_visited[current_node.name]:
      return
    self.already_visited[current_node.name] = True
    for input_node_name in current_node.input:
      input_node_name = node_name_from_input(input_node_name)
      input_node = self.nodes_map[input_node_name]
      self.quantize_nodes_recursively(input_node)
    nodes_to_quantize = ["Conv2D", "BiasAdd", "MatMul"]
    if any(current_node.op in s for s in nodes_to_quantize):
      for input_name in current_node.input:
        input_name = node_name_from_input(input_name)
        input_node = self.nodes_map[input_name]
        self.quantize_node(input_node)
      self.quantize_node(current_node)
    else:
      new_node = node_def_pb2.NodeDef()
      new_node.CopyFrom(current_node)
      self.add_output_graph_node(new_node) 
开发者ID:googlecodelabs,项目名称:tensorflow-for-poets-2,代码行数:22,代码来源:quantize_graph.py

示例11: is_fused_op

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def is_fused_op(node: NodeDef, op_name: Text, activation: Text) -> bool:
    """
    Return whether a node represents a fused TF operation.

    Args:
        node: Node defintion
        op_name: Fused operation name (e.g. 'MatMul')
        activation: Name of the fused activation function (e.g. 'Relu')

    Returns:
        `True`, iff the node is a fused operation with the given activation
    """
    if node.op == f'_Fused{op_name}' and 'fused_ops' in node.attr:
        fused_ops = node.attr['fused_ops'].list.s
        return (len(fused_ops) == 2
                and fused_ops[0] in (b'BiasAdd', b'BiasAddV1')
                and fused_ops[1] == activation)
    return False 
开发者ID:patlevin,项目名称:tfjs-to-tf,代码行数:20,代码来源:graph_rewrite_util.py

示例12: device_function

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def device_function(self, op):
    """Choose a device for `op`.

    Args:
      op: an `Operation`.

    Returns:
      The device to use for the `Operation`.
    """
    # If we don't return early here, either merge_devices is True, or op.device
    # is empty (in which case merging is a no-op). So we can always merge below.
    if not self._merge_devices and op.device:
      return op.device

    current_device = pydev.DeviceSpec.from_string(op.device or "")

    # The ps_device will be used for specified ops (ps_ops) whenever it is
    # present and ps_tasks is non-zero. However, its task number will only be
    # set (using ps_strategy) if there is a job field in ps_device that won't be
    # changed by the job field (if present) in current_device.
    node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
    if self._ps_tasks and self._ps_device and node_def.op in self._ps_ops:
      ps_device = pydev.DeviceSpec.from_string(self._ps_device)

      current_job, ps_job = current_device.job, ps_device.job
      if ps_job and (not current_job or current_job == ps_job):
        ps_device.task = self._ps_strategy(op)

      ps_device.merge_from(current_device)
      return ps_device.to_string()

    worker_device = pydev.DeviceSpec.from_string(self._worker_device or "")
    worker_device.merge_from(current_device)
    return worker_device.to_string() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:36,代码来源:device_setter.py

示例13: _NodeDef

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def _NodeDef(op_type, name, device=None, attrs=None):
  """Create a NodeDef proto.

  Args:
    op_type: Value for the "op" attribute of the NodeDef proto.
    name: Value for the "name" attribute of the NodeDef proto.
    device: string, device, or function from NodeDef to string.
      Value for the "device" attribute of the NodeDef proto.
    attrs: Optional dictionary where the key is the attribute name (a string)
      and the value is the respective "attr" attribute of the NodeDef proto (an
      AttrValue).

  Returns:
    A node_def_pb2.NodeDef protocol buffer.
  """
  node_def = node_def_pb2.NodeDef()
  node_def.op = compat.as_bytes(op_type)
  node_def.name = compat.as_bytes(name)
  if attrs is not None:
    for k, v in six.iteritems(attrs):
      node_def.attr[k].CopyFrom(v)
  if device is not None:
    if callable(device):
      node_def.device = device(node_def)
    else:
      node_def.device = _device_string(device)
  return node_def


# Copied from core/framework/node_def_util.cc
# TODO(mrry,josh11b): Consolidate this validation in C++ code. 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:33,代码来源:ops.py

示例14: _add_control_input

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def _add_control_input(self, op):
    """Add a new control input to this operation.

    Args:
      op: the Operation to add as control input.

    Raises:
      TypeError: if op is not an Operation.
      ValueError: if op is from a different graph.
    """
    self._add_control_inputs([op])

  # Methods below are used when building the NodeDef and Graph proto. 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:ops.py

示例15: node_def

# 需要导入模块: from tensorflow.core.framework import node_def_pb2 [as 别名]
# 或者: from tensorflow.core.framework.node_def_pb2 import NodeDef [as 别名]
def node_def(self):
    """Returns a serialized `NodeDef` representation of this operation.

    Returns:
      A
      [`NodeDef`](https://www.tensorflow.org/code/tensorflow/core/framework/node_def.proto)
      protocol buffer.
    """
    return self._node_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:11,代码来源:ops.py


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