• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python array_ops.reverse_v2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.ops.array_ops.reverse_v2函数的典型用法代码示例。如果您正苦于以下问题:Python reverse_v2函数的具体用法?Python reverse_v2怎么用?Python reverse_v2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: ndlstm_base_dynamic

def ndlstm_base_dynamic(inputs, noutput, scope=None, reverse=False):
  """Run an LSTM, either forward or backward.

  This is a 1D LSTM implementation using dynamic_rnn and
  the TensorFlow LSTM op.

  Args:
    inputs: input sequence (length, batch_size, ninput)
    noutput: depth of output
    scope: optional scope name
    reverse: run LSTM in reverse

  Returns:
    Output sequence (length, batch_size, noutput)
  """
  with variable_scope.variable_scope(scope, "SeqLstm", [inputs]):
    # TODO(tmb) make batch size, sequence_length dynamic
    # example: sequence_length = tf.shape(inputs)[0]
    _, batch_size, _ = _shape(inputs)
    lstm_cell = core_rnn_cell_impl.BasicLSTMCell(noutput, state_is_tuple=False)
    state = array_ops.zeros([batch_size, lstm_cell.state_size])
    sequence_length = int(inputs.get_shape()[0])
    sequence_lengths = math_ops.to_int64(
        array_ops.fill([batch_size], sequence_length))
    if reverse:
      inputs = array_ops.reverse_v2(inputs, [0])
    outputs, _ = rnn.dynamic_rnn(
        lstm_cell, inputs, sequence_lengths, state, time_major=True)
    if reverse:
      outputs = array_ops.reverse_v2(outputs, [0])
    return outputs
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:31,代码来源:lstm1d.py


示例2: _reverse2DimAuto

    def _reverse2DimAuto(self, np_dtype):
        x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np_dtype)

        for use_gpu in [False, True]:
            with self.test_session(use_gpu=use_gpu):
                x_tf_1 = array_ops.reverse_v2(x_np, [0]).eval()
                x_tf_2 = array_ops.reverse_v2(x_np, [-2]).eval()
                x_tf_3 = array_ops.reverse_v2(x_np, [1]).eval()
                x_tf_4 = array_ops.reverse_v2(x_np, [-1]).eval()
                x_tf_5 = array_ops.reverse_v2(x_np, [1, 0]).eval()
                self.assertAllEqual(x_tf_1, np.asarray(x_np)[::-1, :])
                self.assertAllEqual(x_tf_2, np.asarray(x_np)[::-1, :])
                self.assertAllEqual(x_tf_3, np.asarray(x_np)[:, ::-1])
                self.assertAllEqual(x_tf_4, np.asarray(x_np)[:, ::-1])
                self.assertAllEqual(x_tf_5, np.asarray(x_np)[::-1, ::-1])
开发者ID:ppwwyyxx,项目名称:tensorflow,代码行数:15,代码来源:array_ops_test.py


示例3: random_flip_left_right

def random_flip_left_right(image, bboxes, seed=None):
    """Random flip left-right of an image and its bounding boxes.
    """
    def flip_bboxes(bboxes):
        """Flip bounding boxes coordinates.
        """
        bboxes = tf.stack([bboxes[:, 0], 1 - bboxes[:, 3],
                           bboxes[:, 2], 1 - bboxes[:, 1]], axis=-1)
        return bboxes

    # Random flip. Tensorflow implementation.
    with tf.name_scope('random_flip_left_right'):
        image = ops.convert_to_tensor(image, name='image')
        _Check3DImage(image, require_static=False)
        uniform_random = random_ops.random_uniform([], 0, 1.0, seed=seed)
        mirror_cond = math_ops.less(uniform_random, .5)
        # Flip image.
        result = control_flow_ops.cond(mirror_cond,
                                       lambda: array_ops.reverse_v2(image, [1]),
                                       lambda: image)
        # Flip bboxes.
        bboxes = control_flow_ops.cond(mirror_cond,
                                       lambda: flip_bboxes(bboxes),
                                       lambda: bboxes)
        return fix_image_flip_shape(image, result), bboxes
开发者ID:angelocarbone,项目名称:OSSDC-VisionBasedACC,代码行数:25,代码来源:tf_image.py


示例4: _reverse1DimAuto

  def _reverse1DimAuto(self, np_dtype):
    x_np = np.array([1, 200, 3, 40, 5], dtype=np_dtype)

    for use_gpu in [False, True]:
      with self.test_session(use_gpu=use_gpu):
        x_tf = array_ops.reverse_v2(x_np, [0]).eval()
        self.assertAllEqual(x_tf, np.asarray(x_np)[::-1])
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:7,代码来源:array_ops_test.py


示例5: _reverse1DimAuto

  def _reverse1DimAuto(self, np_dtype):
    x_np = np.array([1, 200, 3, 40, 5], dtype=np_dtype)

    for use_gpu in [False, True]:
      for axis_dtype in [dtypes.int32, dtypes.int64]:
        with self.test_session(use_gpu=use_gpu):
          x_tf = array_ops.reverse_v2(x_np,
              constant_op.constant([0], dtype=axis_dtype)).eval()
          self.assertAllEqual(x_tf, np.asarray(x_np)[::-1])
开发者ID:AnddyWang,项目名称:tensorflow,代码行数:9,代码来源:array_ops_test.py


示例6: _auc_convert_hist_to_auc

def _auc_convert_hist_to_auc(hist_true_acc, hist_false_acc, nbins):
  """Convert histograms to auc.

  Args:
    hist_true_acc:  `Tensor` holding accumulated histogram of scores for records
      that were `True`.
    hist_false_acc:  `Tensor` holding accumulated histogram of scores for
      records that were `False`.
    nbins:  Integer number of bins in the histograms.

  Returns:
    Scalar `Tensor` estimating AUC.
  """
  # Note that this follows the "Approximating AUC" section in:
  # Efficient AUC learning curve calculation, R. R. Bouckaert,
  # AI'06 Proceedings of the 19th Australian joint conference on Artificial
  # Intelligence: advances in Artificial Intelligence
  # Pages 181-191.
  # Note that the above paper has an error, and we need to re-order our bins to
  # go from high to low score.

  # Normalize histogram so we get fraction in each bin.
  normed_hist_true = math_ops.truediv(hist_true_acc,
                                      math_ops.reduce_sum(hist_true_acc))
  normed_hist_false = math_ops.truediv(hist_false_acc,
                                       math_ops.reduce_sum(hist_false_acc))

  # These become delta x, delta y from the paper.
  delta_y_t = array_ops.reverse_v2(normed_hist_true, [0], name='delta_y_t')
  delta_x_t = array_ops.reverse_v2(normed_hist_false, [0], name='delta_x_t')

  # strict_1d_cumsum requires float32 args.
  delta_y_t = math_ops.cast(delta_y_t, dtypes.float32)
  delta_x_t = math_ops.cast(delta_x_t, dtypes.float32)

  # Trapezoidal integration, \int_0^1 0.5 * (y_t + y_{t-1}) dx_t
  y_t = _strict_1d_cumsum(delta_y_t, nbins)
  first_trap = delta_x_t[0] * y_t[0] / 2.0
  other_traps = delta_x_t[1:] * (y_t[1:] + y_t[:nbins - 1]) / 2.0
  return math_ops.add(first_trap, math_ops.reduce_sum(other_traps), name='auc')
开发者ID:BloodD,项目名称:tensorflow,代码行数:40,代码来源:histogram_ops.py


示例7: testInvalid

 def testInvalid(self):
     x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
     with self.test_session():
         with self.assertRaisesRegexp(tf.errors.InvalidArgumentError, "is out of valid range"):
             array_ops.reverse_v2(x_np, [-30]).eval()
         with self.assertRaisesRegexp(tf.errors.InvalidArgumentError, "is out of valid range"):
             array_ops.reverse_v2(x_np, [2]).eval()
         with self.assertRaisesRegexp(tf.errors.InvalidArgumentError, "axis 0 specified more than once"):
             array_ops.reverse_v2(x_np, [0, -2]).eval()
开发者ID:ppwwyyxx,项目名称:tensorflow,代码行数:9,代码来源:array_ops_test.py


示例8: ndlstm_base_dynamic

def ndlstm_base_dynamic(inputs, noutput, scope=None, reverse=False):
  """Run an LSTM, either forward or backward.

  This is a 1D LSTM implementation using dynamic_rnn and
  the TensorFlow LSTM op.

  Args:
    inputs: input sequence (length, batch_size, ninput)
    noutput: depth of output
    scope: optional scope name
    reverse: run LSTM in reverse

  Returns:
    Output sequence (length, batch_size, noutput)
  """
  with variable_scope.variable_scope(scope, "SeqLstm", [inputs]):
    lstm_cell = rnn_cell.BasicLSTMCell(noutput)
    if reverse:
      inputs = array_ops.reverse_v2(inputs, [0])
    outputs, _ = rnn.dynamic_rnn(
        lstm_cell, inputs, time_major=True, dtype=inputs.dtype)
    if reverse:
      outputs = array_ops.reverse_v2(outputs, [0])
    return outputs
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:24,代码来源:lstm1d.py


示例9: testInvalidAxis

 def testInvalidAxis(self):
   x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
   with self.assertRaisesRegexp(ValueError,
                                "is out of valid range"):
     array_ops.reverse_v2(x_np, [-30])
   with self.assertRaisesRegexp(ValueError,
                                "is out of valid range"):
     array_ops.reverse_v2(x_np, [2])
   with self.assertRaisesRegexp(ValueError,
                                "axis 0 specified more than once"):
     array_ops.reverse_v2(x_np, [0, -2])
开发者ID:Jackiefan,项目名称:tensorflow,代码行数:11,代码来源:array_ops_test.py


示例10: testInvalid

 def testInvalid(self):
   x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32)
   axis = array_ops.placeholder(dtypes.int32)
   with self.test_session():
     with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
                                  "is out of valid range"):
       array_ops.reverse_v2(x_np, axis).eval(feed_dict={axis: [-30]})
     with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
                                  "is out of valid range"):
       array_ops.reverse_v2(x_np, axis).eval(feed_dict={axis: [2]})
     with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
                                  "axis 0 specified more than once"):
       array_ops.reverse_v2(x_np, axis).eval(feed_dict={axis: [0, -2]})
开发者ID:Jackiefan,项目名称:tensorflow,代码行数:13,代码来源:array_ops_test.py


示例11: _reverse

  def _reverse(self, t, lengths):
    """Time reverse the provided tensor or list of tensors.

    Assumes the top dimension is the time dimension.

    Args:
      t: 3D tensor or list of 2D tensors to be reversed
      lengths: 1D tensor of lengths, or `None`

    Returns:
      A reversed tensor or list of tensors
    """
    if isinstance(t, list):
      return list(reversed(t))
    else:
      if lengths is None:
        return array_ops.reverse_v2(t, [0])
      else:
        return array_ops.reverse_sequence(t, lengths, 0, 1)
开发者ID:BloodD,项目名称:tensorflow,代码行数:19,代码来源:fused_rnn_cell.py


示例12: flip_up_down

def flip_up_down(image):
  """Flip an image horizontally (upside down).

  Outputs the contents of `image` flipped along the first dimension, which is
  `height`.

  See also `reverse()`.

  Args:
    image: A 3-D tensor of shape `[height, width, channels].`

  Returns:
    A 3-D tensor of the same type and shape as `image`.

  Raises:
    ValueError: if the shape of `image` not supported.
  """
  image = ops.convert_to_tensor(image, name='image')
  _Check3DImage(image, require_static=False)
  return fix_image_flip_shape(image, array_ops.reverse_v2(image, [0]))
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:20,代码来源:image_ops_impl.py


示例13: _ReverseV2Grad

def _ReverseV2Grad(op, grad):
  axis = op.inputs[1]
  return array_ops.reverse_v2(grad, axis), None
开发者ID:Jackhuang945,项目名称:tensorflow,代码行数:3,代码来源:array_grad.py


示例14: testReverse0DimAuto

 def testReverse0DimAuto(self):
   x_np = 4
   for use_gpu in [False, True]:
     with self.test_session(use_gpu=use_gpu):
       x_tf = array_ops.reverse_v2(x_np, []).eval()
       self.assertAllEqual(x_tf, x_np)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:6,代码来源:array_ops_test.py


示例15: _rot270

 def _rot270():
   return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]),
                               [1])
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:3,代码来源:image_ops_impl.py


示例16: _rot180

 def _rot180():
   return array_ops.reverse_v2(image, [0, 1])
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:2,代码来源:image_ops_impl.py


示例17: _event_shape

 def _event_shape(self):
   return array_ops.reverse_v2(array_ops.shape(self.alpha), [0])[0]
开发者ID:ivankreso,项目名称:tensorflow,代码行数:2,代码来源:dirichlet_multinomial.py


示例18: _FFTSizeForGrad

def _FFTSizeForGrad(grad, rank):
  return math_ops.reduce_prod(
      array_ops.slice(
          array_ops.reverse_v2(array_ops.shape(grad), [0]), (0,), (rank,)))
开发者ID:curtiszimmerman,项目名称:tensorflow,代码行数:4,代码来源:math_grad.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python array_ops.scatter_nd函数代码示例发布时间:2022-05-27
下一篇:
Python array_ops.reverse_sequence函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap