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


Python tensorflow.NodeDef方法代码示例

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


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

示例1: tf_obj_shape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def tf_obj_shape(input):
    """
    Convert tf objects to shape tuple.

    Arguments:
        input: tf.TensorShape, tf.Tensor, tf.AttrValue or tf.NodeDef
               the corresponding tensorflow object

    Returns:
        tuple: shape of the tensorflow object
    """
    if isinstance(input, tf.TensorShape):
        return tuple([int(i.value) for i in input])
    elif isinstance(input, tf.Tensor):
        return tf_obj_shape(input.get_shape())
    elif isinstance(input, tf.AttrValue):
        return tuple([int(d.size) for d in input.shape.dim])
    elif isinstance(input, tf.NodeDef):
        return tf_obj_shape(input.attr['shape'])
    else:
        raise TypeError("Input to `tf_obj_shape` has the wrong type.") 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:23,代码来源:utils.py

示例2: assign_to_device

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def assign_to_device(self, op_dev, var_dev='/cpu:0'):
    """Returns a function to place variables on the var_dev, and the ops in the
    op_dev.

    Args:
      op_dev: Device for ops
      var_dev: Device for variables
    """
    VAR_OPS = ['Variable', 'VariableV2', 'AutoReloadVariable',
               'MutableHashTable', 'MutableHashTableOfTensors',
               'MutableDenseHashTable']

    def _assign(op):
      node_def = op if isinstance(op, tf.NodeDef) else op.node_def
      if node_def.op in VAR_OPS:
        return "/" + var_dev
      else:
        return op_dev
    return _assign 
开发者ID:PRBonn,项目名称:bonnet,代码行数:21,代码来源:abstract_net.py

示例3: node_from_map

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow 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:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:optimize_for_inference_lib.py

示例4: values_from_const

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow 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:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:optimize_for_inference_lib.py

示例5: quantize_nodes_recursively

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow 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 = tf.NodeDef()
      new_node.CopyFrom(current_node)
      self.add_output_graph_node(new_node) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:22,代码来源:quantize_graph.py

示例6: _split

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def _split(converter, node: Any, inputs: List[str]) -> Any:
    if node.op == "SplitV":
        # node.op is SplitV when num_or_size_splits is a list
        x_in = converter.outputs[inputs[0]]
        size_splits = converter.outputs[inputs[1]]
        axis = converter.outputs[inputs[2]]

        size_splits = size_splits.attr["value"].tensor
        num_or_size_splits = list(array.array("I", size_splits.tensor_content))

    else:
        # node.op is Split when num_or_size_splits is an integer
        axis = converter.outputs[inputs[0]]
        x_in = converter.outputs[inputs[1]]

        num_or_size_splits = node.attr["num_split"].i

    if isinstance(x_in, tf.NodeDef):
        input_out = _nodef_to_private_pond(converter, x_in)
    else:
        input_out = x_in

    axis_val = axis.attr["value"].tensor.int_val[0]

    return tfe.split(input_out, num_or_size_splits, axis_val) 
开发者ID:tf-encrypted,项目名称:tf-encrypted,代码行数:27,代码来源:register.py

示例7: _nodef_to_numpy_array

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def _nodef_to_numpy_array(x):
    """Map a NodeDef x to a np.array."""
    dtype = x.attr["dtype"].type
    x_shape = [i.size for i in x.attr["value"].tensor.tensor_shape.dim]

    content = x.attr["value"].tensor.tensor_content

    if dtype == tf.float32:
        type_code = "f"
        if not content:
            content = x.attr["value"].tensor.float_val
    elif dtype == tf.float64:
        type_code = "d"
        if not content:
            content = x.attr["value"].tensor.double_val
    elif dtype == tf.int32:
        type_code = "i"
        if not content:
            content = x.attr["value"].tensor.int_val
    else:
        raise TypeError("Unsupported dtype")

    nums = array.array(type_code, content)

    return np.array(nums).reshape(x_shape) 
开发者ID:tf-encrypted,项目名称:tf-encrypted,代码行数:27,代码来源:register.py

示例8: variables_device

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def variables_device(self):
    """Returns the device to use for variables created inside the clone.

    Returns:
      A value suitable for `tf.device()`.
    """
    device = ''
    if self._num_ps_tasks > 0:
      device += self._ps_device
    device += '/device:CPU:0'

    class _PSDeviceChooser(object):
      """Slim device chooser for variables when using PS."""

      def __init__(self, device, tasks):
        self._device = device
        self._tasks = tasks
        self._task = 0

      def choose(self, op):
        if op.device:
          return op.device
        node_def = op if isinstance(op, tf.NodeDef) else op.node_def
        if node_def.op.startswith('Variable'):
          t = self._task
          self._task = (self._task + 1) % self._tasks
          d = '%s/task:%d' % (self._device, t)
          return d
        else:
          return op.device

    if not self._num_ps_tasks:
      return device
    else:
      chooser = _PSDeviceChooser(device, self._num_ps_tasks)
      return chooser.choose 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:38,代码来源:model_deploy.py

示例9: variable_device

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def variable_device(device, name):
  """Fix the variable device to colocate its ops."""
  if callable(device):
    var_name = tf.get_variable_scope().name + '/' + name
    var_def = tf.NodeDef(name=var_name, op='Variable')
    device = device(var_def)
  if device is None:
    device = ''
  return device 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:11,代码来源:variables.py

示例10: assign_to_gpu

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def assign_to_gpu(gpu=0, ps_dev="/device:CPU:0"):
    def _assign(op):
        node_def = op if isinstance(op, tf.NodeDef) else op.node_def
        if node_def.op == "Variable":
            return ps_dev
        else:
            return "/gpu:%d" % gpu
    return _assign 
开发者ID:rafaljozefowicz,项目名称:lm,代码行数:10,代码来源:common.py

示例11: assign_to_device

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def assign_to_device(self, device, ps_device="/cpu:0"):
      def _assign(op):
          node_def = op if isinstance(op, tf.NodeDef) else op.node_def
          if node_def.op in self.ps_ops:
              device_name =  ps_device
          else:
              device_name =  device

          # if device_name == "/cpu:0":
          #   print(op.name)
          #   print(device_name)
          #   print('-----------------------------------')
          return device_name
      return _assign 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:16,代码来源:parameter_server_runner.py

示例12: assign_to_device

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import NodeDef [as 别名]
def assign_to_device(self, device, ps_device='/cpu:0'):
        def _assign(op):
            node_def = op if isinstance(op, tf.NodeDef) else op.node_def
            if node_def.op in PS_OPS:
                return "/" + ps_device
            else:
                return device

        return _assign 
开发者ID:chengstone,项目名称:cchess-zero,代码行数:11,代码来源:policy_value_network_gpus.py


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