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


Python compat.as_str方法代碼示例

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


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

示例1: strip_name_scope

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def strip_name_scope(name, export_scope):
  """Removes name scope from a name.

  Args:
    name: A `string` name.
    export_scope: Optional `string`. Name scope to remove.

  Returns:
    Name with name scope removed, or the original name if export_scope
    is None.
  """
  if export_scope:
    try:
      # Strips export_scope/, export_scope///,
      # ^export_scope/, loc:@export_scope/.
      str_to_replace = r"([\^]|loc:@|^)" + export_scope + r"[\/]+(.*)"
      return re.sub(str_to_replace, r"\1\2", compat.as_str(name), count=1)
    except TypeError as e:
      # If the name is not of a type we can process, simply return it.
      logging.warning(e)
      return name
  else:
    return name 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:25,代碼來源:ops.py

示例2: prepend_name_scope

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def prepend_name_scope(name, import_scope):
  """Prepends name scope to a name.

  Args:
    name: A `string` name.
    import_scope: Optional `string`. Name scope to add.

  Returns:
    Name with name scope added, or the original name if import_scope
    is None.
  """
  if import_scope:
    try:
      str_to_replace = r"([\^]|loc:@|^)(.*)"
      return re.sub(str_to_replace, r"\1" + import_scope + r"/\2",
                    compat.as_str(name))
    except TypeError as e:
      # If the name is not of a type we can process, simply return it.
      logging.warning(e)
      return name
  else:
    return name


# pylint: disable=g-doc-return-or-yield 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:27,代碼來源:ops.py

示例3: lookup

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def lookup(self, name):
    """Looks up "name".

    Args:
      name: a string specifying the registry key for the candidate.
    Returns:
      Registered object if found
    Raises:
      LookupError: if "name" has not been registered.
    """
    name = compat.as_str(name)
    if name in self._registry:
      return self._registry[name][_TYPE_TAG]
    else:
      raise LookupError(
          "%s registry has no entry for: %s" % (self._name, name)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:registry.py

示例4: strip_name_scope

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def strip_name_scope(name, export_scope):
  """Removes name scope from a name.

  Args:
    name: A `string` name.
    export_scope: Optional `string`. Name scope to remove.

  Returns:
    Name with name scope removed, or the original name if export_scope
    is None.
  """
  if export_scope:
    # Strips export_scope/, export_scope///,
    # ^export_scope/, loc:@export_scope/.
    str_to_replace = r"([\^]|loc:@|^)" + export_scope + r"[\/]+(.*)"
    return re.sub(str_to_replace, r"\1\2", compat.as_str(name), count=1)
  else:
    return name 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:20,代碼來源:ops.py

示例5: prepend_name_scope

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def prepend_name_scope(name, import_scope):
  """Prepends name scope to a name.

  Args:
    name: A `string` name.
    import_scope: Optional `string`. Name scope to add.

  Returns:
    Name with name scope added, or the original name if import_scope
    is None.
  """
  if import_scope:
    str_to_replace = r"([\^]|loc:@|^)(.*)"
    return re.sub(str_to_replace, r"\1" + import_scope + r"/\2",
                  compat.as_str(name))
  else:
    return name


# pylint: disable=g-doc-return-or-yield 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:22,代碼來源:ops.py

示例6: assert_equal_graph_def

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def assert_equal_graph_def(actual, expected):
  """Asserts that two `GraphDef`s are (mostly) the same.

  Compares two `GraphDef` protos for equality, ignoring versions and ordering of
  nodes, attrs, and control inputs.  Node names are used to match up nodes
  between the graphs, so the naming of nodes must be consistent.

  Args:
    actual: The `GraphDef` we have.
    expected: The `GraphDef` we expected.

  Raises:
    AssertionError: If the `GraphDef`s do not match.
    TypeError: If either argument is not a `GraphDef`.
  """
  if not isinstance(actual, graph_pb2.GraphDef):
    raise TypeError("Expected tf.GraphDef for actual, got %s" %
                    type(actual).__name__)
  if not isinstance(expected, graph_pb2.GraphDef):
    raise TypeError("Expected tf.GraphDef for expected, got %s" %
                    type(expected).__name__)
  diff = pywrap_tensorflow.EqualGraphDefWrapper(actual.SerializeToString(),
                                                expected.SerializeToString())
  if diff:
    raise AssertionError(compat.as_str(diff)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:27,代碼來源:test_util.py

示例7: assert_equal_graph_def

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def assert_equal_graph_def(actual, expected, checkpoint_v2=False):
  """Asserts that two `GraphDef`s are (mostly) the same.

  Compares two `GraphDef` protos for equality, ignoring versions and ordering of
  nodes, attrs, and control inputs.  Node names are used to match up nodes
  between the graphs, so the naming of nodes must be consistent.

  Args:
    actual: The `GraphDef` we have.
    expected: The `GraphDef` we expected.
    checkpoint_v2: boolean determining whether to ignore randomized attribute
        values that appear in V2 checkpoints.

  Raises:
    AssertionError: If the `GraphDef`s do not match.
    TypeError: If either argument is not a `GraphDef`.
  """
  if not isinstance(actual, graph_pb2.GraphDef):
    raise TypeError("Expected tf.GraphDef for actual, got %s" %
                    type(actual).__name__)
  if not isinstance(expected, graph_pb2.GraphDef):
    raise TypeError("Expected tf.GraphDef for expected, got %s" %
                    type(expected).__name__)

  if checkpoint_v2:
    _strip_checkpoint_v2_randomized(actual)
    _strip_checkpoint_v2_randomized(expected)

  diff = pywrap_tensorflow.EqualGraphDefWrapper(actual.SerializeToString(),
                                                expected.SerializeToString())
  if diff:
    raise AssertionError(compat.as_str(diff)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:34,代碼來源:test_util.py

示例8: _CanonicalInputName

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def _CanonicalInputName(input_name):
  input_name = compat.as_str(input_name)
  if _IsControlInput(input_name):
    return input_name
  input_op_name, output_index = _ParseTensorName(input_name)
  return '%s:%d' % (input_op_name, output_index) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:importer.py

示例9: _init_from_proto

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def _init_from_proto(self, hparam_def):
    """Creates a new HParams from `HParamDef` protocol buffer.

    Args:
      hparam_def: `HParamDef` protocol buffer.
    """
    assert isinstance(hparam_def, hparam_pb2.HParamDef)
    for name, value in hparam_def.hparam.items():
      kind = value.WhichOneof('kind')
      if kind.endswith('_value'):
        # Single value.
        if kind.startswith('int64'):
          # Setting attribute value to be 'int' to ensure the type is compatible
          # with both Python2 and Python3.
          self.add_hparam(name, int(getattr(value, kind)))
        elif kind.startswith('bytes'):
          # Setting attribute value to be 'str' to ensure the type is compatible
          # with both Python2 and Python3. UTF-8 encoding is assumed.
          self.add_hparam(name, compat.as_str(getattr(value, kind)))
        else:
          self.add_hparam(name, getattr(value, kind))
      else:
        # List of values.
        if kind.startswith('int64'):
          # Setting attribute value to be 'int' to ensure the type is compatible
          # with both Python2 and Python3.
          self.add_hparam(name, [int(v) for v in getattr(value, kind).value])
        elif kind.startswith('bytes'):
          # Setting attribute value to be 'str' to ensure the type is compatible
          # with both Python2 and Python3. UTF-8 encoding is assumed.
          self.add_hparam(name, [compat.as_str(v)
                                 for v in getattr(value, kind).value])
        else:
          self.add_hparam(name, [v for v in getattr(value, kind).value]) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:36,代碼來源:hparam.py

示例10: assert_equal_graph_def

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def assert_equal_graph_def(actual, expected, checkpoint_v2=False):
  """Asserts that two `GraphDef`s are (mostly) the same.

  Compares two `GraphDef` protos for equality, ignoring versions and ordering of
  nodes, attrs, and control inputs.  Node names are used to match up nodes
  between the graphs, so the naming of nodes must be consistent.

  Args:
    actual: The `GraphDef` we have.
    expected: The `GraphDef` we expected.
    checkpoint_v2: boolean determining whether to ignore randomized attribute
        values that appear in V2 checkpoints.

  Raises:
    AssertionError: If the `GraphDef`s do not match.
    TypeError: If either argument is not a `GraphDef`.
  """
  if not isinstance(actual, graph_pb2.GraphDef):
    raise TypeError("Expected tf.GraphDef for actual, got %s" %
                    type(actual).__name__)
  if not isinstance(expected, graph_pb2.GraphDef):
    raise TypeError("Expected tf.GraphDef for expected, got %s" %
                    type(expected).__name__)

  if checkpoint_v2:
    _strip_checkpoint_v2_randomized(actual)
    _strip_checkpoint_v2_randomized(expected)

  diff = pywrap_tensorflow.EqualGraphDefWrapper(actual.SerializeToString(),
                                                expected.SerializeToString())
  if diff:
    raise AssertionError(compat.as_str(diff))


# Matches attributes named via _SHARDED_SUFFIX in
# tensorflow/python/training/saver.py 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:38,代碼來源:test_util.py

示例11: _init_from_proto

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def _init_from_proto(self, hparam_def):
    """Creates a new HParams from `HParamDef` protocol buffer.
    Args:
      hparam_def: `HParamDef` protocol buffer.
    """
    assert isinstance(hparam_def, hparam_pb2.HParamDef)
    for name, value in hparam_def.hparam.items():
      kind = value.WhichOneof('kind')
      if kind.endswith('_value'):
        # Single value.
        if kind.startswith('int64'):
          # Setting attribute value to be 'int' to ensure the type is compatible
          # with both Python2 and Python3.
          self.add_hparam(name, int(getattr(value, kind)))
        elif kind.startswith('bytes'):
          # Setting attribute value to be 'str' to ensure the type is compatible
          # with both Python2 and Python3. UTF-8 encoding is assumed.
          self.add_hparam(name, compat.as_str(getattr(value, kind)))
        else:
          self.add_hparam(name, getattr(value, kind))
      else:
        # List of values.
        if kind.startswith('int64'):
          # Setting attribute value to be 'int' to ensure the type is compatible
          # with both Python2 and Python3.
          self.add_hparam(name, [int(v) for v in getattr(value, kind).value])
        elif kind.startswith('bytes'):
          # Setting attribute value to be 'str' to ensure the type is compatible
          # with both Python2 and Python3. UTF-8 encoding is assumed.
          self.add_hparam(
              name, [compat.as_str(v) for v in getattr(value, kind).value])
        else:
          self.add_hparam(name, [v for v in getattr(value, kind).value]) 
開發者ID:IntelAI,項目名稱:models,代碼行數:35,代碼來源:hparam.py

示例12: gpu_device_name

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def gpu_device_name():
  """Returns the name of a GPU device if available or the empty string."""
  for x in device_lib.list_local_devices():
    if x.device_type == "GPU" or x.device_type == "SYCL":
      return compat.as_str(x.name)
  return "" 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:8,代碼來源:test_util.py

示例13: _set_c_attrs

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def _set_c_attrs(self, attrs):
    """Sets `attrs` as attributes of self._c_func.

    Requires that self._c_func is not None.

    Args:
      attrs: a dictionary from attribute name to attribute proto value
    """
    for name, attr_value in attrs.items():
      serialized = attr_value.SerializeToString()
      # TODO(skyewm): this creates and deletes a new TF_Status for every attr.
      # It might be worth creating a convenient way to re-use the same status.
      with errors.raise_exception_on_not_ok_status() as status:
        c_api.TF_FunctionSetAttrValueProto(self._c_func, compat.as_str(name),
                                           serialized, status) 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:17,代碼來源:function.py

示例14: _create_c_op

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def _create_c_op(self, graph, node_def, inputs, control_inputs):
    """Creates a TF_Operation.

    Arguments:
      graph: a `Graph`.
      node_def: `node_def_pb2.NodeDef` for the operation to create.
      inputs: A list of `Tensor`s (corresponding to scalar inputs) and lists of
        `Tensor`s (corresponding to sequence inputs, e.g. "int64 * N",
        "list(int64)"). The length of the list should be equal to the number of
        inputs specified by this operation's op def.
      control_inputs: A list of `Operation`s to set as control dependencies.

    Returns:
      A wrapped TF_Operation*.
    """
    # pylint: disable=protected-access
    op_desc = c_api.TF_NewOperation(graph._c_graph.g,
                                    compat.as_str(node_def.op),
                                    compat.as_str(node_def.name))
    # Add inputs
    for op_input in inputs:
      if isinstance(op_input, (list, tuple)):
        c_api.TF_AddInputList(op_desc, [t._as_tf_output() for t in op_input])
      else:
        c_api.TF_AddInput(op_desc, op_input._as_tf_output())

    # Add control inputs
    for control_input in control_inputs:
      c_api.TF_AddControlInput(op_desc, control_input._c_op)
    # pylint: enable=protected-access

    # Add attrs
    for name, attr_value in node_def.attr.items():
      serialized = attr_value.SerializeToString()
      # TODO(skyewm): this creates and deletes a new TF_Status for every attr.
      # It might be worth creating a convenient way to re-use the same status.
      with errors.raise_exception_on_not_ok_status() as status:
        c_api.TF_SetAttrValueProto(op_desc, compat.as_str(name), serialized,
                                   status)

    with errors.raise_exception_on_not_ok_status() as status:
      c_op = c_api.TF_FinishOperation(op_desc, status)

    return c_op 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:46,代碼來源:ops.py

示例15: _node_def

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str [as 別名]
def _node_def(from_node_def, export_scope, unbound_inputs, clear_devices=False):
  """Create a `NodeDef` proto with export_scope stripped.

  Args:
    from_node_def: A `node_def_pb2.NodeDef` protocol buffer.
    export_scope: A `string` representing the name scope to remove.
    unbound_inputs: An array of unbound input names if they exist.
    clear_devices: Boolean which controls whether to clear device information
      from node_def. Default false.

  Returns:
    A `node_def_pb2.NodeDef` protocol buffer.
  """
  node_def = copy.deepcopy(from_node_def)
  for i, v in enumerate(node_def.input):
    if (export_scope and
        not node_def.input[i].lstrip("^").startswith(export_scope)):
      # Adds "$unbound_inputs_" prefix to the unbound name so they are easily
      # identifiable.
      node_def.input[i] = re.sub(r"([\^]|^)(.*)",
                                 r"\1" + _UNBOUND_INPUT_PREFIX + r"\2",
                                 compat.as_str(v))
      unbound_inputs.append(node_def.input[i])
    else:
      node_def.input[i] = ops.strip_name_scope(v, export_scope)
  node_def.name = compat.as_bytes(
      ops.strip_name_scope(from_node_def.name, export_scope))
  for k, v in six.iteritems(from_node_def.attr):
    if k == "_class":
      new_s = [compat.as_bytes(
          ops.strip_name_scope(s, export_scope)) for s in v.list.s
               if not export_scope or
               compat.as_str(s).split("@")[1].startswith(export_scope)]
      node_def.attr[k].CopyFrom(attr_value_pb2.AttrValue(
          list=attr_value_pb2.AttrValue.ListValue(s=new_s)))
    else:
      node_def.attr[k].CopyFrom(v)

  if clear_devices:
    node_def.device = ""

  return node_def 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:44,代碼來源:meta_graph.py


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