Python tensorflow.python.ops.array_ops.reverse_v2() Examples
The following are 30
code examples of tensorflow.python.ops.array_ops.reverse_v2().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.array_ops
, or try the search function
.
Example #1
Source File: array_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testUnknownDims(self): reverse_v2 = array_ops.reverse_v2 data_t = tf.placeholder(tf.float32) axis_known_t = tf.placeholder(tf.int32, shape=[3]) reverse_known_t = reverse_v2(data_t, axis_known_t) # Unlike V1 we cannot know this anymore self.assertEqual(None, reverse_known_t.get_shape().ndims) axis_unknown_t = tf.placeholder(tf.int32) reverse_unknown_t = reverse_v2(data_t, axis_unknown_t) self.assertIs(None, reverse_unknown_t.get_shape().ndims) data_2d_t = tf.placeholder(tf.float32, shape=[None, None]) axis_2d_t = tf.placeholder(tf.int32, shape=[3]) reverse_2d_t = reverse_v2(data_2d_t, axis_2d_t) self.assertEqual(2, reverse_2d_t.get_shape().ndims)
Example #2
Source File: tf_image.py From HUAWEIOCR-2019 with MIT License | 6 votes |
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
Example #3
Source File: tf_image.py From X-Detector with Apache License 2.0 | 6 votes |
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
Example #4
Source File: image_ops_impl.py From keras-lambda with MIT License | 6 votes |
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]))
Example #5
Source File: tf_image.py From pixel_link with MIT License | 6 votes |
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
Example #6
Source File: tf_image.py From MobileNet with Apache License 2.0 | 6 votes |
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
Example #7
Source File: tf_image.py From seglink with GNU General Public License v3.0 | 6 votes |
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
Example #8
Source File: array_ops_test.py From deep_image_model with Apache License 2.0 | 6 votes |
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]) # This is the version of reverse that uses axis indices rather than # bool tensors # TODO(b/32254538): Change this test to use array_ops.reverse
Example #9
Source File: image_ops_impl.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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]))
Example #10
Source File: fused_rnn_cell.py From lambda-packs with MIT License | 6 votes |
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)
Example #11
Source File: array_grad.py From lambda-packs with MIT License | 5 votes |
def _ReverseV2Grad(op, grad): axis = op.inputs[1] return array_ops.reverse_v2(grad, axis), None
Example #12
Source File: lstm1d.py From keras-lambda with MIT License | 5 votes |
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
Example #13
Source File: dirichlet_multinomial.py From keras-lambda with MIT License | 5 votes |
def _event_shape(self): return array_ops.reverse_v2(array_ops.shape(self.alpha), [0])[0]
Example #14
Source File: math_grad.py From keras-lambda with MIT License | 5 votes |
def _FFTSizeForGrad(grad, rank): return math_ops.reduce_prod( array_ops.slice( array_ops.reverse_v2(array_ops.shape(grad), [0]), (0,), (rank,)))
Example #15
Source File: image_ops_impl.py From keras-lambda with MIT License | 5 votes |
def rot90(image, k=1, name=None): """Rotate an image counter-clockwise by 90 degrees. Args: image: A 3-D tensor of shape `[height, width, channels]`. k: A scalar integer. The number of times the image is rotated by 90 degrees. name: A name for this operation (optional). Returns: A rotated 3-D tensor of the same type and shape as `image`. """ with ops.name_scope(name, 'rot90', [image, k]) as scope: image = ops.convert_to_tensor(image, name='image') _Check3DImage(image, require_static=False) k = ops.convert_to_tensor(k, dtype=dtypes.int32, name='k') k.get_shape().assert_has_rank(0) k = math_ops.mod(k, 4) def _rot90(): return array_ops.transpose(array_ops.reverse_v2(image, [1]), [1, 0, 2]) def _rot180(): return array_ops.reverse_v2(image, [0, 1]) def _rot270(): return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]), [1]) cases = [(math_ops.equal(k, 1), _rot90), (math_ops.equal(k, 2), _rot180), (math_ops.equal(k, 3), _rot270)] ret = control_flow_ops.case(cases, default=lambda: image, exclusive=True, name=scope) ret.set_shape([None, None, image.get_shape()[2]]) return ret
Example #16
Source File: image_ops_impl.py From lambda-packs with MIT License | 5 votes |
def rot90(image, k=1, name=None): """Rotate an image counter-clockwise by 90 degrees. Args: image: A 3-D tensor of shape `[height, width, channels]`. k: A scalar integer. The number of times the image is rotated by 90 degrees. name: A name for this operation (optional). Returns: A rotated 3-D tensor of the same type and shape as `image`. """ with ops.name_scope(name, 'rot90', [image, k]) as scope: image = ops.convert_to_tensor(image, name='image') image = control_flow_ops.with_dependencies( _Check3DImage(image, require_static=False), image) k = ops.convert_to_tensor(k, dtype=dtypes.int32, name='k') k.get_shape().assert_has_rank(0) k = math_ops.mod(k, 4) def _rot90(): return array_ops.transpose(array_ops.reverse_v2(image, [1]), [1, 0, 2]) def _rot180(): return array_ops.reverse_v2(image, [0, 1]) def _rot270(): return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]), [1]) cases = [(math_ops.equal(k, 1), _rot90), (math_ops.equal(k, 2), _rot180), (math_ops.equal(k, 3), _rot270)] ret = control_flow_ops.case(cases, default=lambda: image, exclusive=True, name=scope) ret.set_shape([None, None, image.get_shape()[2]]) return ret
Example #17
Source File: array_grad.py From keras-lambda with MIT License | 5 votes |
def _ReverseV2Grad(op, grad): axis = op.inputs[1] return array_ops.reverse_v2(grad, axis), None
Example #18
Source File: official_tf_image.py From X-Detector with Apache License 2.0 | 5 votes |
def rot90(image, k=1, name=None): """Rotate an image counter-clockwise by 90 degrees. Args: image: A 3-D tensor of shape `[height, width, channels]`. k: A scalar integer. The number of times the image is rotated by 90 degrees. name: A name for this operation (optional). Returns: A rotated 3-D tensor of the same type and shape as `image`. """ with ops.name_scope(name, 'rot90', [image, k]) as scope: image = ops.convert_to_tensor(image, name='image') image = control_flow_ops.with_dependencies( _Check3DImage(image, require_static=False), image) k = ops.convert_to_tensor(k, dtype=dtypes.int32, name='k') k.get_shape().assert_has_rank(0) k = math_ops.mod(k, 4) def _rot90(): return array_ops.transpose(array_ops.reverse_v2(image, [1]), [1, 0, 2]) def _rot180(): return array_ops.reverse_v2(image, [0, 1]) def _rot270(): return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]), [1]) cases = [(math_ops.equal(k, 1), _rot90), (math_ops.equal(k, 2), _rot180), (math_ops.equal(k, 3), _rot270)] ret = control_flow_ops.case(cases, default=lambda: image, exclusive=True, name=scope) ret.set_shape([None, None, image.get_shape()[2]]) return ret
Example #19
Source File: image_ops_impl.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def rot90(image, k=1, name=None): """Rotate an image counter-clockwise by 90 degrees. Args: image: A 3-D tensor of shape `[height, width, channels]`. k: A scalar integer. The number of times the image is rotated by 90 degrees. name: A name for this operation (optional). Returns: A rotated 3-D tensor of the same type and shape as `image`. """ with ops.name_scope(name, 'rot90', [image, k]) as scope: image = ops.convert_to_tensor(image, name='image') image = control_flow_ops.with_dependencies( _Check3DImage(image, require_static=False), image) k = ops.convert_to_tensor(k, dtype=dtypes.int32, name='k') k.get_shape().assert_has_rank(0) k = math_ops.mod(k, 4) def _rot90(): return array_ops.transpose(array_ops.reverse_v2(image, [1]), [1, 0, 2]) def _rot180(): return array_ops.reverse_v2(image, [0, 1]) def _rot270(): return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]), [1]) cases = [(math_ops.equal(k, 1), _rot90), (math_ops.equal(k, 2), _rot180), (math_ops.equal(k, 3), _rot270)] ret = control_flow_ops.case(cases, default=lambda: image, exclusive=True, name=scope) ret.set_shape([None, None, image.get_shape()[2]]) return ret
Example #20
Source File: array_grad.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _ReverseV2Grad(op, grad): axis = op.inputs[1] return array_ops.reverse_v2(grad, axis), None
Example #21
Source File: tf_image.py From SSD_tensorflow_VOC with Apache License 2.0 | 5 votes |
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) #debugging info # mirror_cond = tf.Print(mirror_cond, [mirror_cond], 'flipped image') # 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
Example #22
Source File: array_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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()
Example #23
Source File: array_grad.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _ReverseV2Grad(op, grad): axis = op.inputs[1] return array_ops.reverse_v2(grad, axis), None
Example #24
Source File: array_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def _reverse1DimAuto(self, np_dtype): x_np = np.array([1, 2, 3, 4, 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])
Example #25
Source File: array_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: histogram_ops.py From tf-slim with Apache License 2.0 | 5 votes |
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')
Example #27
Source File: dirichlet_multinomial.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _event_shape(self): return array_ops.reverse_v2(array_ops.shape(self.alpha), [0])[0]
Example #28
Source File: lstm1d.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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
Example #29
Source File: math_grad.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _FFTSizeForGrad(grad, rank): return math_ops.reduce_prod( array_ops.slice( array_ops.reverse_v2(array_ops.shape(grad), [0]), (0,), (rank,)))
Example #30
Source File: image_ops_impl.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def rot90(image, k=1, name=None): """Rotate an image counter-clockwise by 90 degrees. Args: image: A 3-D tensor of shape `[height, width, channels]`. k: A scalar integer. The number of times the image is rotated by 90 degrees. name: A name for this operation (optional). Returns: A rotated 3-D tensor of the same type and shape as `image`. """ with ops.name_scope(name, 'rot90', [image, k]) as scope: image = ops.convert_to_tensor(image, name='image') _Check3DImage(image, require_static=False) k = ops.convert_to_tensor(k, dtype=dtypes.int32, name='k') k.get_shape().assert_has_rank(0) k = math_ops.mod(k, 4) def _rot90(): return array_ops.transpose(array_ops.reverse_v2(image, [1]), [1, 0, 2]) def _rot180(): return array_ops.reverse_v2(image, [0, 1]) def _rot270(): return array_ops.reverse_v2(array_ops.transpose(image, [1, 0, 2]), [1]) cases = [(math_ops.equal(k, 1), _rot90), (math_ops.equal(k, 2), _rot180), (math_ops.equal(k, 3), _rot270)] ret = control_flow_ops.case(cases, default=lambda: image, exclusive=True, name=scope) ret.set_shape([None, None, image.get_shape()[2]]) return ret