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


Python string_ops.string_join方法代码示例

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


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

示例1: _check_multiple_of

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _check_multiple_of(value, multiple_of):
  """Checks that value `value` is a non-zero multiple of `multiple_of`.

  Args:
    value: an int32 scalar Tensor.
    multiple_of: an int or int32 scalar Tensor.

  Returns:
    new_value: an int32 scalar Tensor matching `value`, but which includes an
      assertion that `value` is a multiple of `multiple_of`.
  """
  assert isinstance(value, ops.Tensor)
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.logical_and(
              math_ops.equal(math_ops.mod(value, multiple_of), 0),
              math_ops.not_equal(value, 0)), [
                  string_ops.string_join([
                      "Tensor %s should be a multiple of: " % value.name,
                      string_ops.as_string(multiple_of), ", but saw value: ",
                      string_ops.as_string(value),
                      ". Consider setting pad=True."
                  ])
              ])
  ]):
    new_value = array_ops.identity(value, name="multiple_of_checked")
    return new_value 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:29,代码来源:sequence_queueing_state_saver.py

示例2: _check_rank

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _check_rank(value, expected_rank):
  """Check the rank of Tensor `value`, via shape inference and assertions.

  Args:
    value: A Tensor, possibly with shape associated shape information.
    expected_rank: int32 scalar (optionally a `Tensor`).

  Returns:
    new_value: A Tensor matching `value`.  Accessing this tensor tests
      assertions on its rank.  If expected_rank is not a `Tensor`, then
      new_value's shape's rank has been set.

  Raises:
    ValueError: if `expected_rank` is not a `Tensor` and the rank of `value`
      is known and is not equal to `expected_rank`.
  """
  assert isinstance(value, ops.Tensor)
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.equal(expected_rank, array_ops.rank(value)), [
              string_ops.string_join([
                  "Rank of tensor %s should be: " % value.name,
                  string_ops.as_string(expected_rank), ", shape received:"
              ]), array_ops.shape(value)
          ])
  ]):
    new_value = array_ops.identity(value, name="rank_checked")
    if isinstance(expected_rank, ops.Tensor):
      expected_rank_value = tensor_util.constant_value(expected_rank)
      if expected_rank_value is not None:
        expected_rank = int(expected_rank_value)
    if not isinstance(expected_rank, ops.Tensor):
      try:
        new_value.set_shape(new_value.get_shape().with_rank(expected_rank))
      except ValueError as e:
        raise ValueError("Rank check failed for %s: %s" % (value.name, str(e)))
    return new_value 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:39,代码来源:sequence_queueing_state_saver.py

示例3: _check_multiple_of

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _check_multiple_of(value, multiple_of):
  """Checks that value `value` is a non-zero multiple of `multiple_of`.

  Args:
    value: an int32 scalar Tensor.
    multiple_of: an int or int32 scalar Tensor.

  Returns:
    new_value: an int32 scalar Tensor matching `value`, but which includes an
      assertion that `value` is a multiple of `multiple_of`.
  """
  assert isinstance(value, ops.Tensor)
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.logical_and(
              math_ops.equal(math_ops.mod(value, multiple_of), 0),
              math_ops.not_equal(value, 0)),
          [string_ops.string_join(
              ["Tensor %s should be a multiple of: " % value.name,
               string_ops.as_string(multiple_of),
               ", but saw value: ",
               string_ops.as_string(value),
               ". Consider setting pad=True."])])]):
    new_value = array_ops.identity(
        value, name="multiple_of_checked")
    return new_value 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:28,代码来源:sequence_queueing_state_saver.py

示例4: _check_rank

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _check_rank(value, expected_rank):
  """Check the rank of Tensor `value`, via shape inference and assertions.

  Args:
    value: A Tensor, possibly with shape associated shape information.
    expected_rank: int32 scalar (optionally a `Tensor`).

  Returns:
    new_value: A Tensor matching `value`.  Accessing this tensor tests
      assertions on its rank.  If expected_rank is not a `Tensor`, then
      new_value's shape's rank has been set.

  Raises:
    ValueError: if `expected_rank` is not a `Tensor` and the rank of `value`
      is known and is not equal to `expected_rank`.
  """
  assert isinstance(value, ops.Tensor)
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.equal(expected_rank, array_ops.rank(value)),
          [string_ops.string_join(
              ["Rank of tensor %s should be: " % value.name,
               string_ops.as_string(expected_rank),
               ", shape received:"]),
           array_ops.shape(value)])]):
    new_value = array_ops.identity(value, name="rank_checked")
    if isinstance(expected_rank, ops.Tensor):
      expected_rank_value = tensor_util.constant_value(expected_rank)
      if expected_rank_value is not None:
        expected_rank = int(expected_rank_value)
    if not isinstance(expected_rank, ops.Tensor):
      try:
        new_value.set_shape(new_value.get_shape().with_rank(expected_rank))
      except ValueError as e:
        raise ValueError("Rank check failed for %s: %s"
                         % (value.name, str(e)))
    return new_value 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:39,代码来源:sequence_queueing_state_saver.py

示例5: _check_shape

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _check_shape(value, expected_shape):
  """Check the shape of Tensor `value`, via shape inference and assertions.

  Args:
    value: A Tensor, possibly with shape associated shape information.
    expected_shape: a `TensorShape`, list of `int32`, or a vector `Tensor`.

  Returns:
    new_value: A Tensor matching `value`.  Accessing this tensor tests
      assertions on its shape.  If expected_shape is not a `Tensor`, then
      new_value's shape has been set.

  Raises:
    ValueError: if `expected_shape` is not a `Tensor` and the shape of `value`
      is known and is not equal to `expected_shape`.
  """
  assert isinstance(value, ops.Tensor)
  if isinstance(expected_shape, tensor_shape.TensorShape):
    expected_shape = expected_shape.as_list()
  if isinstance(expected_shape, ops.Tensor):
    expected_shape_value = tensor_util.constant_value(expected_shape)
    if expected_shape_value is not None:
      expected_shape = [int(d) for d in expected_shape_value]
  if isinstance(expected_shape, ops.Tensor):
    value = _check_rank(value, array_ops.size(expected_shape))
  else:
    value = _check_rank(value, len(expected_shape))
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.reduce_all(
              math_ops.equal(expected_shape, array_ops.shape(value))), [
                  string_ops.string_join([
                      "Shape of tensor %s should be: " % value.name,
                      string_ops.as_string(expected_shape),
                      ", shape received: ",
                      string_ops.as_string(array_ops.shape(value))
                  ])
              ])
  ]):
    new_value = array_ops.identity(value, name="shape_checked")
    if not isinstance(expected_shape, ops.Tensor):
      try:
        new_value.set_shape(new_value.get_shape().merge_with(expected_shape))
      except ValueError as e:
        raise ValueError("Shape check failed for %s: %s" % (value.name, str(e)))
    return new_value 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:48,代码来源:sequence_queueing_state_saver.py

示例6: _check_shape

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _check_shape(value, expected_shape):
  """Check the shape of Tensor `value`, via shape inference and assertions.

  Args:
    value: A Tensor, possibly with shape associated shape information.
    expected_shape: a `TensorShape`, list of `int32`, or a vector `Tensor`.

  Returns:
    new_value: A Tensor matching `value`.  Accessing this tensor tests
      assertions on its shape.  If expected_shape is not a `Tensor`, then
      new_value's shape has been set.

  Raises:
    ValueError: if `expected_shape` is not a `Tensor` and the shape of `value`
      is known and is not equal to `expected_shape`.
  """
  assert isinstance(value, ops.Tensor)
  if isinstance(expected_shape, tensor_shape.TensorShape):
    expected_shape = expected_shape.as_list()
  if isinstance(expected_shape, ops.Tensor):
    expected_shape_value = tensor_util.constant_value(expected_shape)
    if expected_shape_value is not None:
      expected_shape = [int(d) for d in expected_shape_value]
  if isinstance(expected_shape, ops.Tensor):
    value = _check_rank(value, array_ops.size(expected_shape))
  else:
    value = _check_rank(value, len(expected_shape))
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.reduce_all(math_ops.equal(expected_shape, array_ops.shape(
              value))), [string_ops.string_join([
                  "Shape of tensor %s should be: " % value.name,
                  string_ops.as_string(expected_shape), ", shape received: ",
                  string_ops.as_string(array_ops.shape(value))
              ])])
  ]):
    new_value = array_ops.identity(value, name="shape_checked")
    if not isinstance(expected_shape, ops.Tensor):
      try:
        new_value.set_shape(new_value.get_shape().merge_with(expected_shape))
      except ValueError as e:
        raise ValueError("Shape check failed for %s: %s"
                         % (value.name, str(e)))
    return new_value 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:46,代码来源:sequence_queueing_state_saver.py

示例7: _padding

# 需要导入模块: from tensorflow.python.ops import string_ops [as 别名]
# 或者: from tensorflow.python.ops.string_ops import string_join [as 别名]
def _padding(sequences, num_unroll):
  """For a dictionary of sequences, pads tensors to a multiple of `num_unroll`.

  Args:
    sequences: dictionary with `Tensor` values.
    num_unroll: int specifying to what multiple to pad sequences to.
  Returns:
    length: Scalar `Tensor` of dimension 0 of all the values in sequences.
    padded_sequence: Dictionary of sequences that are padded to a multiple of
      `num_unroll`.
  Raises:
    ValueError: If `num_unroll` not an int or sequences not a dictionary from
                string to `Tensor`.
  """
  if not isinstance(num_unroll, numbers.Integral):
    raise ValueError("Unsupported num_unroll expected int, got: %s" %
                     str(num_unroll))
  if not isinstance(sequences, dict):
    raise TypeError("Unsupported sequences expected dict, got: %s" %
                    str(sequences))
  for key, value in sequences.items():
    if not isinstance(key, six.string_types):
      raise TypeError("Unsupported sequences key expected string, got: %s" %
                      str(key))
  if not sequences:
    return 0, {}

  sequences_dict = {}
  for key, value in sequences.items():
    sequences_dict[key] = ops.convert_to_tensor(value)

  lengths = [array_ops.shape(value)[0] for value in sequences_dict.values()]
  length = lengths[0]
  all_lengths_equal = [
      control_flow_ops.Assert(
          math_ops.equal(l, length), [string_ops.string_join(
              ["All sequence lengths must match, but received lengths: ",
               string_ops.as_string(lengths)])])
      for l in lengths]

  length = control_flow_ops.with_dependencies(all_lengths_equal, length)
  unroll = array_ops.constant(num_unroll)
  padded_length = length + ((unroll - (length % unroll)) % unroll)
  padded_sequences = {}
  for key, value in sequences_dict.items():
    # 1. create shape of paddings
    # first dimension of value will be increased by num_paddings to
    # padded_length
    num_paddings = [padded_length - array_ops.shape(value)[0]]
    # the shape of the paddings that we concat with the original value will be
    # [num_paddings, tf.shape(value)[1], tf.shape(value)[2], ...,
    #  tf.shape(value)[tf.rank(value) - 1])]
    padding_shape = array_ops.concat(0, (
        num_paddings, array_ops.shape(value)[1:]))
    # 2. fill padding shape with dummies
    dummy = array_ops.constant("" if value.dtype == dtypes.string else 0,
                               dtype=value.dtype)
    paddings = array_ops.fill(dims=padding_shape, value=dummy)
    # 3. concat values with paddings
    padded_sequences[key] = array_ops.concat(0, [value, paddings])
  return length, padded_sequences 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:63,代码来源:sequence_queueing_state_saver.py


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