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


Python attr_value_pb2.AttrValue方法代码示例

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


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

示例1: _parse_kwargs_as_attrs

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _parse_kwargs_as_attrs(func_name, **kwargs):
  """Parses **kwargs into a node's attributes."""
  attrs = {}

  noinline = kwargs.pop("noinline", None)
  if noinline is not None:
    attrs["_noinline"] = attr_value_pb2.AttrValue(b=bool(noinline))

  compiled = kwargs.pop("compiled", None)
  separate_compiled_gradients = kwargs.pop("separate_compiled_gradients", None)
  if compiled is not None:
    attrs["_XlaCompile"] = attr_value_pb2.AttrValue(b=bool(compiled))
    attrs["_XlaSeparateCompiledGradients"] = attr_value_pb2.AttrValue(
        b=bool(separate_compiled_gradients))
    attrs["_XlaScope"] = attr_value_pb2.AttrValue(
        s=("function_%s" % func_name).encode())

  if kwargs:
    raise ValueError("Unknown keyword arguments: %s" % kwargs.keys())
  return attrs 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:function.py

示例2: experimental_jit_scope

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def experimental_jit_scope(compile_ops=True):
  """Enable or disable JIT compilation of operators within the scope.

  NOTE: This is an experimental feature.

  The compilation is a hint and only supported on a best-effort basis.

  Example usage:
    with tf.contrib.framework.experimental_jit_scope():
      c = tf.matmul(a, b)  # compiled
    with tf.contrib.framework.experimental_jit_scope(compile_ops=False):
        d = tf.matmul(a, c)  # not compiled

  Args:
    compile_ops: boolean, whether to enable or disable compilation in the scope.
  Yields:
    The current scope, enabling or disabling compilation.

  """
  attrs = {"_XlaCompile": attr_value_pb2.AttrValue(b=compile_ops)}
  # pylint: disable=protected-access
  with ops.get_default_graph()._attr_scope(attrs):
    yield
  # pylint: enable=protected-access 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:26,代码来源:jit.py

示例3: _add_input_array

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _add_input_array(op, start, limit, dtype, func):
  """Adds a _ListToArray node in the func for op.inputs[start:limit]."""
  node = function_pb2.FunctionDef.Node()
  node.op = "_ListToArray"
  ret_name = op.name + "_L2A_" + str(start)
  node.ret.extend([ret_name])
  node.arg.extend(
      [_make_argname_from_tensor_name(x.name) for x in op.inputs[start:limit]])
  num = limit - start
  node.attr["Tin"].CopyFrom(
      attr_value_pb2.AttrValue(list=attr_value_pb2.AttrValue.ListValue(
          type=[dtype] * num)))
  node.attr["T"].CopyFrom(attr_value_pb2.AttrValue(type=dtype))
  node.attr["N"].CopyFrom(attr_value_pb2.AttrValue(i=num))
  func.node.extend([node])
  return ret_name 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:function.py

示例4: _add_output_list

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _add_output_list(op, start, limit, dtype_lst, func):
  """Adds a _ArrayToList node in the func for op.outputs[start:limit]."""
  ret_name = op.name + "_Lst_" + str(start) + "_" + str(limit)
  num = limit - start
  assert len(dtype_lst) == num
  # Adds an identity node for each element in the array N*T so that
  # uses of each element can be added easily later. These Identity
  # will be eliminated before graph execution.
  for i in xrange(num):
    node = function_pb2.FunctionDef.Node()
    node.op = "Identity"
    node.arg.append(ret_name + ":" + str(i))
    node.ret.append(_make_argname_from_tensor_name(op.outputs[i].name))
    node.attr["T"].CopyFrom(attr_value_pb2.AttrValue(type=dtype_lst[i]))
    func.node.extend([node])
  return ret_name 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:function.py

示例5: testLabelMap

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def testLabelMap(self):
    with self.test_session() as sess:
      a1 = self._get_test_attrs()
      with sess.graph._attr_scope(
          {"_A": attr_value_pb2.AttrValue(s=compat.as_bytes("foo"))}):
        a2 = self._get_test_attrs()
        with sess.graph._attr_scope(
            {"_A": None,
             "_B": attr_value_pb2.AttrValue(s=compat.as_bytes("bar"))}):
          a3 = self._get_test_attrs()
          with sess.graph._attr_scope(
              {"_A": attr_value_pb2.AttrValue(s=compat.as_bytes("baz"))}):
            a4 = self._get_test_attrs()
          a5 = self._get_test_attrs()
        a6 = self._get_test_attrs()
      a7 = self._get_test_attrs()

      self.assertAllEqual((None, None), a1)
      self.assertAllEqual(("foo", None), a2)
      self.assertAllEqual((None, "bar"), a3)
      self.assertAllEqual(("baz", "bar"), a4)
      self.assertAllEqual((None, "bar"), a5)
      self.assertAllEqual(("foo", None), a6)
      self.assertAllEqual((None, None), a7) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:26,代码来源:ops_test.py

示例6: test_parse_tensor

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def test_parse_tensor(self):
        # Zero-rank tensor
        attr = attr_value.AttrValue()
        attr.tensor.version_number = 1
        attr.tensor.dtype = types.DataType.DT_INT32
        t = parse.parse_attr(attr)
        self.assertTrue(isinstance(t, mil_types.int32))
        self.assertEqual(0, t.val)

        # Non-zero rank
        attr = attr_value.AttrValue()
        attr.tensor.version_number = 1
        attr.tensor.dtype = types.DataType.DT_INT32
        shaped_attr = self._attr_with_shape([(1, "outer"), (2, "middle"), (3, "inner")])
        attr.tensor.tensor_shape.dim.extend(shaped_attr.shape.dim)
        attr.tensor.int_val.extend([55, 56, 57])

        t = parse.parse_attr(attr)
        self.assertEqual([55, 56, 57], t.val.tolist())
        self.assertEqual("tensor", mil_types.get_type_info(t).name)

        # Note that the result of t.get_primitive() is a function that returns a type
        # rather than an instance of that type as it is when the tensor has rank zero.
        self.assertTrue(isinstance(t.get_primitive()(), mil_types.int32))
        self.assertEqual((1, 2, 3), t.get_shape()) 
开发者ID:apple,项目名称:coremltools,代码行数:27,代码来源:test_parse.py

示例7: _populate_const_op

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _populate_const_op(output_node, node_name, dtype, data, data_shape):
  """Creates a Const op.

  Args:
    output_node: TensorFlow NodeDef.
    node_name: str node name.
    dtype: AttrValue with a populated .type field.
    data: numpy data value.
    data_shape: Tuple of integers containing data shape.
  """
  output_node.op = "Const"
  output_node.name = node_name
  output_node.attr["dtype"].CopyFrom(dtype)
  tensor = tensor_util.make_tensor_proto(
      data, dtype=dtype.type, shape=data_shape)
  output_node.attr["value"].tensor.CopyFrom(tensor) 
开发者ID:onnx,项目名称:keras-onnx,代码行数:18,代码来源:_graph_cvt.py

示例8: _populate_if_op

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _populate_if_op(output_node, input_node, function_data):
  """Updates the type attributes and function names of If or StatelessIf.

  Args:
    output_node: TensorFlow NodeDef.
    input_node: TensorFlow NodeDef.
    function_data: Map of function names to the list of types and shapes that
      correspond with the function arguments.
  """
  output_node.CopyFrom(input_node)
  then_func = input_node.attr["then_branch"].func.name
  output_node.attr["then_branch"].func.name = _get_new_function_name(then_func)
  output_node.attr["else_branch"].func.name = _get_new_function_name(
      input_node.attr["else_branch"].func.name)
  output_node.attr["Tin"].list.CopyFrom(
      attr_value_pb2.AttrValue.ListValue(
          type=function_data[then_func]["types"])) 
开发者ID:onnx,项目名称:keras-onnx,代码行数:19,代码来源:_graph_cvt.py

示例9: _populate_while_op

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _populate_while_op(output_node, input_node, function_data):
  """Updates the type attributes and function names of While or StatelessWhile.

  Args:
    output_node: TensorFlow NodeDef.
    input_node: TensorFlow NodeDef.
    function_data: Map of function names to the list of types and shapes that
      correspond with the function arguments.
  """
  output_node.CopyFrom(input_node)
  cond_func = input_node.attr["cond"].func.name
  output_node.attr["cond"].func.name = _get_new_function_name(cond_func)
  output_node.attr["body"].func.name = _get_new_function_name(
      input_node.attr["body"].func.name)
  output_node.attr["T"].list.CopyFrom(
      attr_value_pb2.AttrValue.ListValue(
          type=function_data[cond_func]["types"]))
  output_node.attr["output_shapes"].list.CopyFrom(
      attr_value_pb2.AttrValue.ListValue(
          shape=function_data[cond_func]["shapes"])) 
开发者ID:onnx,项目名称:keras-onnx,代码行数:22,代码来源:_graph_cvt.py

示例10: _MaybeCompile

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def _MaybeCompile(scope, op, func, grad_fn):
  """Compile the calculation in grad_fn if op was marked as compiled."""
  scope = scope.rstrip("/").replace("/", "_")
  if func is not None:
    xla_compile = func.definition.attr["_XlaCompile"].b
    xla_separate_compiled_gradients = func.definition.attr[
        "_XlaSeparateCompiledGradients"].b
    xla_scope = func.definition.attr["_XlaScope"].s.decode()
  else:
    try:
      xla_compile = op.get_attr("_XlaCompile")
      xla_separate_compiled_gradients = op.get_attr(
          "_XlaSeparateCompiledGradients")
      xla_scope = op.get_attr("_XlaScope").decode()
    except ValueError:
      return grad_fn()  # Exit early

  if not xla_compile:
    return grad_fn()  # Exit early

  # If the gradients are supposed to be compiled separately, we give them a
  # _XlaScope name that is based on the name_scope of the gradients.  Otherwise
  # they just inherit the existing _XlaScope name, which lets them be merged
  # together with the non-gradient computation.
  if xla_separate_compiled_gradients:
    xla_grad_scope = "%s_grad_%s" % (xla_scope, scope)
  else:
    xla_grad_scope = xla_scope

  attrs = {
      "_XlaCompile": attr_value_pb2.AttrValue(b=xla_compile),
      "_XlaScope": attr_value_pb2.AttrValue(s=xla_grad_scope.encode())
  }
  with ops.get_default_graph()._attr_scope(attrs):  # pylint: disable=protected-access
    return grad_fn() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:37,代码来源:gradients_impl.py

示例11: optimize_for_inference

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def optimize_for_inference(input_graph_def, input_node_names, output_node_names,
                           placeholder_type_enum):
  """Applies a series of inference optimizations on the input graph.

  Args:
    input_graph_def: A GraphDef containing a training model.
    input_node_names: A list of names of the nodes that are fed inputs during
      inference.
    output_node_names: A list of names of the nodes that produce the final
      results.
    placeholder_type_enum: The AttrValue enum for the placeholder data type, or
        a list that specifies one value per input node name.

  Returns:
    An optimized version of the input graph.
  """
  ensure_graph_is_valid(input_graph_def)
  optimized_graph_def = input_graph_def
  optimized_graph_def = strip_unused_lib.strip_unused(optimized_graph_def,
                                                      input_node_names,
                                                      output_node_names,
                                                      placeholder_type_enum)
  optimized_graph_def = graph_util.remove_training_nodes(optimized_graph_def)
  optimized_graph_def = fold_batch_norms(optimized_graph_def)
  optimized_graph_def = fuse_resize_and_conv(optimized_graph_def,
                                             output_node_names)
  ensure_graph_is_valid(optimized_graph_def)
  return optimized_graph_def 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:optimize_for_inference_lib.py

示例12: _NodeDef

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

示例13: strip_unused

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def strip_unused(input_graph_def, input_node_names, output_node_names,
                 placeholder_type_enum):
  """Removes unused nodes from a GraphDef.

  Args:
    input_graph_def: A graph with nodes we want to prune.
    input_node_names: A list of the nodes we use as inputs.
    output_node_names: A list of the output nodes.
    placeholder_type_enum: The AttrValue enum for the placeholder data type, or
        a list that specifies one value per input node name.

  Returns:
    A GraphDef with all unnecessary ops removed.
  """
  # Here we replace the nodes we're going to override as inputs with
  # placeholders so that any unused nodes that are inputs to them are
  # automatically stripped out by extract_sub_graph().
  inputs_replaced_graph_def = graph_pb2.GraphDef()
  for node in input_graph_def.node:
    if node.name in input_node_names:
      placeholder_node = node_def_pb2.NodeDef()
      placeholder_node.op = "Placeholder"
      placeholder_node.name = node.name
      if isinstance(placeholder_type_enum, list):
        input_node_index = input_node_names.index(node.name)
        placeholder_node.attr["dtype"].CopyFrom(
            attr_value_pb2.AttrValue(type=placeholder_type_enum[
                input_node_index]))
      else:
        placeholder_node.attr["dtype"].CopyFrom(
            attr_value_pb2.AttrValue(type=placeholder_type_enum))
      if "_output_shapes" in node.attr:
        placeholder_node.attr["_output_shapes"].CopyFrom(node.attr[
            "_output_shapes"])
      inputs_replaced_graph_def.node.extend([placeholder_node])
    else:
      inputs_replaced_graph_def.node.extend([copy.deepcopy(node)])

  output_graph_def = graph_util.extract_sub_graph(inputs_replaced_graph_def,
                                                  output_node_names)
  return output_graph_def 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:43,代码来源:strip_unused_lib.py

示例14: set_attr_dtype

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def set_attr_dtype(self, node, key, value):
    node.attr[key].CopyFrom(
        attr_value_pb2.AttrValue(type=value.as_datatype_enum)) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:5,代码来源:optimize_for_inference_test.py

示例15: set_attr_tensor

# 需要导入模块: from tensorflow.core.framework import attr_value_pb2 [as 别名]
# 或者: from tensorflow.core.framework.attr_value_pb2 import AttrValue [as 别名]
def set_attr_tensor(self, node, key, value, dtype, shape=None):
    node.attr[key].CopyFrom(
        attr_value_pb2.AttrValue(tensor=tensor_util.make_tensor_proto(
            value, dtype=dtype, shape=shape))) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:6,代码来源:optimize_for_inference_test.py


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