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


Python compat.as_str_any方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def __init__(self, handle, dtype, session):
    """Constructs a new tensor handle.

    A tensor handle for a persistent tensor is a python string
    that has the form of "tensor_name;unique_id;device_name".

    Args:
      handle: A tensor handle.
      dtype: The data type of the tensor represented by `handle`.
      session: The session in which the tensor is produced.
    """
    self._handle = compat.as_str_any(handle)
    self._resource_handle = None
    self._dtype = dtype
    self._session = session
    self._auto_gc_enabled = True 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:session_ops.py

示例2: get_summary_description

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def get_summary_description(node_def):
  """Given a TensorSummary node_def, retrieve its SummaryDescription.

  When a Summary op is instantiated, a SummaryDescription of associated
  metadata is stored in its NodeDef. This method retrieves the description.

  Args:
    node_def: the node_def_pb2.NodeDef of a TensorSummary op

  Returns:
    a summary_pb2.SummaryDescription

  Raises:
    ValueError: if the node is not a summary op.
  """

  if node_def.op != 'TensorSummary':
    raise ValueError("Can't get_summary_description on %s" % node_def.op)
  description_str = _compat.as_str_any(node_def.attr['description'].s)
  summary_description = SummaryDescription()
  _json_format.Parse(description_str, summary_description)
  return summary_description 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:summary.py

示例3: get_matching_files

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def get_matching_files(filename):
  """Returns a list of files that match the given pattern.

  Args:
    filename: string, the pattern

  Returns:
    Returns a list of strings containing filenames that match the given pattern.

  Raises:
    errors.OpError: If there are filesystem / directory listing errors.
  """
  with errors.raise_exception_on_not_ok_status() as status:
    # Convert each element to string, since the return values of the
    # vector of string should be interpreted as strings, not bytes.
    return [compat.as_str_any(matching_filename)
            for matching_filename in pywrap_tensorflow.GetMatchingFiles(
                compat.as_bytes(filename), status)] 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:20,代碼來源:file_io.py

示例4: relu6

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def relu6(op, context):
  input_name = make_tensor(op.inputs[0], context)
  output_name = compat.as_str_any(op.outputs[0].name)

  relu_output_name = 'relu_' + output_name
  context.builder.add_activation(
      relu_output_name, 'RELU', input_name, relu_output_name)
  neg_output_name = relu_output_name + '_neg'
  # negate it
  context.builder.add_activation(
      neg_output_name, 'LINEAR', relu_output_name, neg_output_name, [-1.0, 0])
  # apply threshold
  clip_output_name = relu_output_name + '_clip'
  context.builder.add_unary(
      clip_output_name, neg_output_name, clip_output_name, 'threshold',
      alpha=-6.0)
  # negate it back
  context.builder.add_activation(
      output_name, 'LINEAR', clip_output_name, output_name, [-1.0, 0])
  context.translated[output_name] = True 
開發者ID:tf-coreml,項目名稱:tf-coreml,代碼行數:22,代碼來源:_layers.py

示例5: product

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def product(op, context):

  input_name = make_tensor(op.inputs[0], context)
  output_name = compat.as_str_any(op.outputs[0].name)
  start_ind = context.consts[op.inputs[1].name]

  assert start_ind == 0, 'Prod: only start index = 0 case supported'

  input_shape = context.shape_dict[input_name]

  if len(input_shape) == 1:
    axis = 'C'
  else:
    assert False, 'Reduce Sum axis case not handled currently'

  mode = 'prod'
  context.translated[output_name] = True
  context.builder.add_reduce(output_name, input_name, output_name, axis, mode) 
開發者ID:tf-coreml,項目名稱:tf-coreml,代碼行數:20,代碼來源:_layers.py

示例6: one_hot

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def one_hot(op, context):
  input_name = compat.as_str_any(op.inputs[0].name)
  output_name = compat.as_str_any(op.outputs[0].name)

  depth = context.consts[compat.as_str_any(op.inputs[1].name)]
  on_value = context.consts[compat.as_str_any(op.inputs[2].name)]
  off_value = context.consts[compat.as_str_any(op.inputs[3].name)]

  n_dims = depth
  W = np.ones((depth, depth)) * off_value
  for i in range(depth):
    W[i, i] = on_value
  context.builder.add_embedding(name=output_name,
                                W=W,
                                b=None,
                                input_dim=n_dims,
                                output_channels=n_dims,
                                has_bias=False,
                                input_name=input_name,
                                output_name=output_name)
  context.translated[output_name] = True 
開發者ID:tf-coreml,項目名稱:tf-coreml,代碼行數:23,代碼來源:_layers.py

示例7: lrn

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def lrn(op, context):
  input_name = make_tensor(op.inputs[0], context)
  output_name = compat.as_str_any(op.outputs[0].name)

  input_shape = context.shape_dict[input_name]
  C = input_shape[-1]
  alpha = op.get_attr('alpha')
  beta = op.get_attr('beta')
  bias = op.get_attr('bias')
  depth_radius = op.get_attr('depth_radius')
  context.builder.add_lrn(output_name, input_name, output_name,
                          alpha=alpha * C,
                          beta=beta,
                          local_size=depth_radius,
                          k=bias)
  context.translated[output_name] = True 
開發者ID:tf-coreml,項目名稱:tf-coreml,代碼行數:18,代碼來源:_layers.py

示例8: identity

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def identity(op, context, input_name = None, input_id = 0):
  is_network_output = False
  for out in op.outputs:
    if out.name in context.output_names:
      is_network_output = True
      break
  if input_name is None:
    input_name = compat.as_str_any(op.inputs[input_id].name)
  for out in op.outputs:
    output_name = compat.as_str_any(out.name)
    if op.inputs[input_id].op.type != 'Const':
      if is_network_output:
        context.builder.add_activation(
            output_name, 'LINEAR', input_name, output_name, [1.0, 0])
      else:
        skip(op, context)
    context.translated[output_name] = True 
開發者ID:tf-coreml,項目名稱:tf-coreml,代碼行數:19,代碼來源:_layers_common.py

示例9: _export_eval_result

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def _export_eval_result(self, eval_result, checkpoint_path,
                            is_the_final_export):
      """Export `eval_result` according to exporters in `EvalSpec`."""
      export_dir_base = os.path.join(
          compat.as_str_any(self._estimator.model_dir),
          compat.as_str_any('export'))

      for exporter in self._eval_spec.exporters:
        exporter.export(
            estimator=self._estimator,
            export_path=os.path.join(
                compat.as_str_any(export_dir_base),
                compat.as_str_any(exporter.name)),
            checkpoint_path=checkpoint_path,
            eval_result=eval_result,
            is_the_final_export=is_the_final_export) 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:18,代碼來源:training.py

示例10: list_directory

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def list_directory(dirname):
  """Returns a list of entries contained within a directory.

  The list is in arbitrary order. It does not contain the special entries "."
  and "..".

  Args:
    dirname: string, path to a directory

  Returns:
    [filename1, filename2, ... filenameN] as strings

  Raises:
    errors.NotFoundError if directory doesn't exist
  """
  if not is_directory(dirname):
    raise errors.NotFoundError(None, None, "Could not find directory")
  with errors.raise_exception_on_not_ok_status() as status:
    # Convert each element to string, since the return values of the
    # vector of string should be interpreted as strings, not bytes.
    return [
        compat.as_str_any(filename)
        for filename in pywrap_tensorflow.GetChildren(
            compat.as_bytes(dirname), status)
    ] 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:27,代碼來源:file_io.py

示例11: _get_device_name

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def _get_device_name(handle):
    """The device name encoded in the handle."""
    handle_str = compat.as_str_any(handle)
    return pydev.canonical_name(handle_str.split(";")[-1]) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:session_ops.py

示例12: _prepare_value

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def _prepare_value(self, val):
    if self._binary_mode:
      return compat.as_bytes(val)
    else:
      return compat.as_str_any(val) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:7,代碼來源:file_io.py

示例13: get_matching_files

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def get_matching_files(filename):
  """Returns a list of files that match the given pattern(s).

  Args:
    filename: string or iterable of strings. The glob pattern(s).

  Returns:
    A list of strings containing filenames that match the given pattern(s).

  Raises:
    errors.OpError: If there are filesystem / directory listing errors.
  """
  with errors.raise_exception_on_not_ok_status() as status:
    if isinstance(filename, six.string_types):
      return [
          # Convert the filenames to string from bytes.
          compat.as_str_any(matching_filename)
          for matching_filename in pywrap_tensorflow.GetMatchingFiles(
              compat.as_bytes(filename), status)
      ]
    else:
      return [
          # Convert the filenames to string from bytes.
          compat.as_str_any(matching_filename)
          for single_filename in filename
          for matching_filename in pywrap_tensorflow.GetMatchingFiles(
              compat.as_bytes(single_filename), status)
      ] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:30,代碼來源:file_io.py

示例14: walk

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def walk(top, in_order=True):
  """Recursive directory tree generator for directories.

  Args:
    top: string, a Directory name
    in_order: bool, Traverse in order if True, post order if False.

  Errors that happen while listing directories are ignored.

  Yields:
    Each yield is a 3-tuple:  the pathname of a directory, followed by lists of
    all its subdirectories and leaf files.
    (dirname, [subdirname, subdirname, ...], [filename, filename, ...])
    as strings
  """
  top = compat.as_str_any(top)
  try:
    listing = list_directory(top)
  except errors.NotFoundError:
    return

  files = []
  subdirs = []
  for item in listing:
    full_path = os.path.join(top, item)
    if is_directory(full_path):
      subdirs.append(item)
    else:
      files.append(item)

  here = (top, subdirs, files)

  if in_order:
    yield here

  for subdir in subdirs:
    for subitem in walk(os.path.join(top, subdir), in_order):
      yield subitem

  if not in_order:
    yield here 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:43,代碼來源:file_io.py

示例15: IsTensorFlowEventsFile

# 需要導入模塊: from tensorflow.python.util import compat [as 別名]
# 或者: from tensorflow.python.util.compat import as_str_any [as 別名]
def IsTensorFlowEventsFile(path):
  """Check the path name to see if it is probably a TF Events file.

  Args:
    path: A file path to check if it is an event file.

  Raises:
    ValueError: If the path is an empty string.

  Returns:
    If path is formatted like a TensorFlowEventsFile.
  """
  if not path:
    raise ValueError('Path must be a nonempty string')
  return 'tfevents' in compat.as_str_any(os.path.basename(path)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:17,代碼來源:event_accumulator.py


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