# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for image preprocessing layers."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from absl.testing import parameterized
import numpy as np

from tensorflow.python.compat import compat
from tensorflow.python.framework import errors
from tensorflow.python.framework import test_util as tf_test_util
from tensorflow.python.keras import keras_parameterized
from tensorflow.python.keras import testing_utils
from tensorflow.python.keras.layers.preprocessing import image_preprocessing
from tensorflow.python.keras.utils.generic_utils import CustomObjectScope
from tensorflow.python.ops import gen_stateful_random_ops
from tensorflow.python.ops import image_ops_impl as image_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import stateless_random_ops
from tensorflow.python.platform import test


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class ResizingTest(keras_parameterized.TestCase):

  def _run_test(self, kwargs, expected_height, expected_width):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    kwargs.update({'height': expected_height, 'width': expected_width})
    with tf_test_util.use_gpu():
      testing_utils.layer_test(
          image_preprocessing.Resizing,
          kwargs=kwargs,
          input_shape=(num_samples, orig_height, orig_width, channels),
          expected_output_shape=(None, expected_height, expected_width,
                                 channels))

  @parameterized.named_parameters(
      ('down_sample_bilinear_2_by_2', {'interpolation': 'bilinear'}, 2, 2),
      ('down_sample_bilinear_3_by_2', {'interpolation': 'bilinear'}, 3, 2),
      ('down_sample_nearest_2_by_2', {'interpolation': 'nearest'}, 2, 2),
      ('down_sample_nearest_3_by_2', {'interpolation': 'nearest'}, 3, 2),
      ('down_sample_area_2_by_2', {'interpolation': 'area'}, 2, 2),
      ('down_sample_area_3_by_2', {'interpolation': 'area'}, 3, 2))
  def test_down_sampling(self, kwargs, expected_height, expected_width):
    with CustomObjectScope({'Resizing': image_preprocessing.Resizing}):
      self._run_test(kwargs, expected_height, expected_width)

  @parameterized.named_parameters(
      ('up_sample_bilinear_10_by_12', {'interpolation': 'bilinear'}, 10, 12),
      ('up_sample_bilinear_12_by_12', {'interpolation': 'bilinear'}, 12, 12),
      ('up_sample_nearest_10_by_12', {'interpolation': 'nearest'}, 10, 12),
      ('up_sample_nearest_12_by_12', {'interpolation': 'nearest'}, 12, 12),
      ('up_sample_area_10_by_12', {'interpolation': 'area'}, 10, 12),
      ('up_sample_area_12_by_12', {'interpolation': 'area'}, 12, 12))
  def test_up_sampling(self, kwargs, expected_height, expected_width):
    with CustomObjectScope({'Resizing': image_preprocessing.Resizing}):
      self._run_test(kwargs, expected_height, expected_width)

  @parameterized.named_parameters(
      ('reshape_bilinear_10_by_4', {'interpolation': 'bilinear'}, 10, 4))
  def test_reshaping(self, kwargs, expected_height, expected_width):
    with CustomObjectScope({'Resizing': image_preprocessing.Resizing}):
      self._run_test(kwargs, expected_height, expected_width)

  def test_invalid_interpolation(self):
    with self.assertRaises(NotImplementedError):
      image_preprocessing.Resizing(5, 5, 'invalid_interpolation')

  def test_config_with_custom_name(self):
    layer = image_preprocessing.Resizing(5, 5, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.Resizing.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


def get_numpy_center_crop(images, expected_height, expected_width):
  orig_height = images.shape[1]
  orig_width = images.shape[2]
  height_start = int((orig_height - expected_height) / 2)
  width_start = int((orig_width - expected_width) / 2)
  height_end = height_start + expected_height
  width_end = width_start + expected_width
  return images[:, height_start:height_end, width_start:width_end, :]


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class CenterCropTest(keras_parameterized.TestCase):

  def _run_test(self, expected_height, expected_width):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    kwargs = {'height': expected_height, 'width': expected_width}
    input_images = np.random.random(
        (num_samples, orig_height, orig_width, channels)).astype(np.float32)
    expected_output = get_numpy_center_crop(
        input_images, expected_height, expected_width)
    with tf_test_util.use_gpu():
      testing_utils.layer_test(
          image_preprocessing.CenterCrop,
          kwargs=kwargs,
          input_shape=(num_samples, orig_height, orig_width, channels),
          input_data=input_images,
          expected_output=expected_output,
          expected_output_shape=(None, expected_height, expected_width,
                                 channels))

  @parameterized.named_parameters(
      ('center_crop_3_by_4', 3, 4),
      ('center_crop_3_by_2', 3, 2))
  def test_center_crop_aligned(self, expected_height, expected_width):
    with CustomObjectScope({'CenterCrop': image_preprocessing.CenterCrop}):
      self._run_test(expected_height, expected_width)

  @parameterized.named_parameters(
      ('center_crop_4_by_5', 4, 5),
      ('center_crop_4_by_3', 4, 3))
  def test_center_crop_mis_aligned(self, expected_height, expected_width):
    with CustomObjectScope({'CenterCrop': image_preprocessing.CenterCrop}):
      self._run_test(expected_height, expected_width)

  @parameterized.named_parameters(
      ('center_crop_4_by_6', 4, 6),
      ('center_crop_3_by_2', 3, 2))
  def test_center_crop_half_mis_aligned(self, expected_height, expected_width):
    with CustomObjectScope({'CenterCrop': image_preprocessing.CenterCrop}):
      self._run_test(expected_height, expected_width)

  @parameterized.named_parameters(
      ('center_crop_5_by_12', 5, 12),
      ('center_crop_10_by_8', 10, 8),
      ('center_crop_10_by_12', 10, 12))
  def test_invalid_center_crop(self, expected_height, expected_width):
    with self.assertRaisesRegexp(errors.InvalidArgumentError,
                                 r'assertion failed'):
      self._run_test(expected_height, expected_width)

  def test_config_with_custom_name(self):
    layer = image_preprocessing.CenterCrop(5, 5, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.CenterCrop.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomCropTest(keras_parameterized.TestCase):

  def _run_test(self, expected_height, expected_width):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    kwargs = {'height': expected_height, 'width': expected_width}
    with tf_test_util.use_gpu():
      testing_utils.layer_test(
          image_preprocessing.RandomCrop,
          kwargs=kwargs,
          input_shape=(num_samples, orig_height, orig_width, channels),
          expected_output_shape=(None, expected_height, expected_width,
                                 channels))

  @parameterized.named_parameters(
      ('random_crop_5_by_12', 5, 12),
      ('random_crop_10_by_8', 10, 8),
      ('random_crop_10_by_12', 10, 12))
  def test_invalid_random_crop(self, expected_height, expected_width):
    with self.assertRaises(errors.InvalidArgumentError):
      with CustomObjectScope({'RandomCrop': image_preprocessing.RandomCrop}):
        self._run_test(expected_height, expected_width)

  def test_training_with_mock(self):
    if test.is_built_with_rocm():
      # TODO(rocm):
      # re-enable this test once ROCm adds support for
      # the StatefulUniformFullInt Op (on the GPU)
      self.skipTest('Feature not supported on ROCm')
    np.random.seed(1337)
    height, width = 3, 4
    height_offset = np.random.randint(low=0, high=3)
    width_offset = np.random.randint(low=0, high=5)
    mock_offset = [0, height_offset, width_offset, 0]
    with test.mock.patch.object(
        stateless_random_ops, 'stateless_random_uniform',
        return_value=mock_offset):
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomCrop(height, width)
        inp = np.random.random((12, 5, 8, 3))
        actual_output = layer(inp, training=1)
        expected_output = inp[:, height_offset:(height_offset + height),
                              width_offset:(width_offset + width), :]
        self.assertAllClose(expected_output, actual_output)

  @parameterized.named_parameters(
      ('random_crop_4_by_6', 4, 6),
      ('random_crop_3_by_2', 3, 2))
  def test_random_crop_output_shape(self, expected_height, expected_width):
    if test.is_built_with_rocm():
      # TODO(rocm):
      # re-enable this test once ROCm adds support for
      # the StatefulUniformFullInt Op (on the GPU)
      self.skipTest('Feature not supported on ROCm')
    with CustomObjectScope({'RandomCrop': image_preprocessing.RandomCrop}):
      self._run_test(expected_height, expected_width)

  def test_predicting_with_mock_longer_height(self):
    np.random.seed(1337)
    height, width = 3, 3
    inp = np.random.random((12, 10, 6, 3))
    with tf_test_util.use_gpu():
      layer = image_preprocessing.RandomCrop(height, width)
      actual_output = layer(inp, training=0)
      resized_inp = image_ops.resize_images_v2(
          inp, size=[5, 3])
      expected_output = resized_inp[:, 1:4, :, :]
      self.assertAllClose(expected_output, actual_output)

  def test_predicting_with_mock_longer_width(self):
    np.random.seed(1337)
    height, width = 4, 6
    inp = np.random.random((12, 8, 16, 3))
    with tf_test_util.use_gpu():
      layer = image_preprocessing.RandomCrop(height, width)
      actual_output = layer(inp, training=0)
      resized_inp = image_ops.resize_images_v2(
          inp, size=[4, 8])
      expected_output = resized_inp[:, :, 1:7, :]
      self.assertAllClose(expected_output, actual_output)

  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomCrop(5, 5, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomCrop.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


class RescalingTest(keras_parameterized.TestCase):

  @keras_parameterized.run_all_keras_modes(always_skip_v1=True)
  def test_rescaling_base(self):
    kwargs = {'scale': 0.004}
    testing_utils.layer_test(
        image_preprocessing.Rescaling,
        kwargs=kwargs,
        input_shape=(2, 5, 6, 3),
        expected_output_shape=(None, 5, 6, 3))

  @tf_test_util.run_v2_only
  def test_rescaling_correctness_float(self):
    layer = image_preprocessing.Rescaling(0.004)
    inputs = random_ops.random_uniform((2, 4, 5, 3))
    outputs = layer(inputs)
    self.assertAllClose(outputs.numpy(), inputs.numpy() * 0.004)

  @tf_test_util.run_v2_only
  def test_rescaling_correctness_int(self):
    layer = image_preprocessing.Rescaling(0.004)
    inputs = random_ops.random_uniform((2, 4, 5, 3), 0, 100, dtype='int32')
    outputs = layer(inputs)
    self.assertEqual(outputs.dtype.name, 'float32')
    self.assertAllClose(outputs.numpy(), inputs.numpy() * 0.004)

  def test_config_with_custom_name(self):
    layer = image_preprocessing.Rescaling(0.5, name='rescaling')
    config = layer.get_config()
    layer_1 = image_preprocessing.Rescaling.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomFlipTest(keras_parameterized.TestCase):

  def _run_test(self, mode, expected_output=None, mock_random=None):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    if mock_random is None:
      mock_random = [1 for _ in range(num_samples)]
      mock_random = np.reshape(mock_random, [2, 1, 1, 1])
    inp = np.random.random((num_samples, orig_height, orig_width, channels))
    if expected_output is None:
      expected_output = inp
      if mode == 'horizontal' or mode == 'horizontal_and_vertical':
        expected_output = np.flip(expected_output, axis=1)
      if mode == 'vertical' or mode == 'horizontal_and_vertical':
        expected_output = np.flip(expected_output, axis=2)
    with test.mock.patch.object(
        random_ops, 'random_uniform', return_value=mock_random):
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomFlip(mode)
        actual_output = layer(inp, training=1)
        self.assertAllClose(expected_output, actual_output)

  @parameterized.named_parameters(
      ('random_flip_horizontal', 'horizontal'),
      ('random_flip_vertical', 'vertical'),
      ('random_flip_both', 'horizontal_and_vertical'))
  def test_random_flip(self, mode):
    with CustomObjectScope({'RandomFlip': image_preprocessing.RandomFlip}):
      self._run_test(mode)

  def test_random_flip_horizontal_half(self):
    with CustomObjectScope({'RandomFlip': image_preprocessing.RandomFlip}):
      np.random.seed(1337)
      mock_random = [1, 0]
      mock_random = np.reshape(mock_random, [2, 1, 1, 1])
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images.copy()
      expected_output[0, :, :, :] = np.flip(input_images[0, :, :, :], axis=0)
      self._run_test('horizontal', expected_output, mock_random)

  def test_random_flip_vertical_half(self):
    with CustomObjectScope({'RandomFlip': image_preprocessing.RandomFlip}):
      np.random.seed(1337)
      mock_random = [1, 0]
      mock_random = np.reshape(mock_random, [2, 1, 1, 1])
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images.copy()
      expected_output[0, :, :, :] = np.flip(input_images[0, :, :, :], axis=1)
      self._run_test('vertical', expected_output, mock_random)

  def test_random_flip_inference(self):
    with CustomObjectScope({'RandomFlip': image_preprocessing.RandomFlip}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomFlip()
        actual_output = layer(input_images, training=0)
        self.assertAllClose(expected_output, actual_output)

  def test_random_flip_default(self):
    with CustomObjectScope({'RandomFlip': image_preprocessing.RandomFlip}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = np.flip(np.flip(input_images, axis=1), axis=2)
      mock_random = [1, 1]
      mock_random = np.reshape(mock_random, [2, 1, 1, 1])
      with test.mock.patch.object(
          random_ops, 'random_uniform', return_value=mock_random):
        with self.cached_session(use_gpu=True):
          layer = image_preprocessing.RandomFlip()
          actual_output = layer(input_images, training=1)
          self.assertAllClose(expected_output, actual_output)

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomFlip(name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomFlip.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomContrastTest(keras_parameterized.TestCase):

  def _run_test(self,
                lower,
                upper,
                expected_output=None,
                mock_random=None):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    if mock_random is None:
      mock_random = 0.2
    inp = np.random.random((num_samples, orig_height, orig_width, channels))
    if expected_output is None:
      # reduce mean on height.
      inp_mean = np.mean(inp, axis=1, keepdims=True)
      # reduce mean on width.
      inp_mean = np.mean(inp_mean, axis=2, keepdims=True)
      expected_output = (inp - inp_mean) * mock_random + inp_mean
    with test.mock.patch.object(
        random_ops, 'random_uniform', return_value=mock_random):
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomContrast((lower, upper))
        actual_output = layer(inp, training=True)
        self.assertAllClose(expected_output, actual_output)

  @parameterized.named_parameters(
      ('random_contrast_2_by_5', 0.2, 0.5),
      ('random_contrast_2_by_13', 0.2, 1.3),
      ('random_contrast_5_by_2', 0.5, 0.2))
  def test_random_contrast(self, lower, upper):
    with CustomObjectScope(
        {'RandomContrast': image_preprocessing.RandomContrast}):
      self._run_test(lower, upper)

  @parameterized.named_parameters(
      ('random_contrast_amplitude_2', 0.2),
      ('random_contrast_amplitude_5', 0.5))
  def test_random_contrast_amplitude(self, amplitude):
    with CustomObjectScope(
        {'RandomContrast': image_preprocessing.RandomContrast}):
      input_images = np.random.random((2, 5, 8, 3))
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomContrast(amplitude)
        layer(input_images)

  def test_random_contrast_inference(self):
    with CustomObjectScope(
        {'RandomContrast': image_preprocessing.RandomContrast}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomContrast((0.1, 0.2))
        actual_output = layer(input_images, training=False)
        self.assertAllClose(expected_output, actual_output)

  def test_random_contrast_int_dtype(self):
    with CustomObjectScope(
        {'RandomContrast': image_preprocessing.RandomContrast}):
      input_images = np.random.randint(low=0, high=255, size=(2, 5, 8, 3))
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomContrast((0.1, 0.2))
        layer(input_images)

  def test_random_contrast_invalid_bounds(self):
    with self.assertRaises(ValueError):
      image_preprocessing.RandomContrast((-0.1, .5))

    with self.assertRaises(ValueError):
      image_preprocessing.RandomContrast((1.1, .5))

    with self.assertRaises(ValueError):
      image_preprocessing.RandomContrast((0.1, -0.2))

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomContrast((.5, .6), name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomContrast.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomTranslationTest(keras_parameterized.TestCase):

  def _run_test(self, height_factor, width_factor):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    kwargs = {'height_factor': height_factor, 'width_factor': width_factor}
    with tf_test_util.use_gpu():
      testing_utils.layer_test(
          image_preprocessing.RandomTranslation,
          kwargs=kwargs,
          input_shape=(num_samples, orig_height, orig_width, channels),
          expected_output_shape=(None, orig_height, orig_width, channels))

  @parameterized.named_parameters(
      ('random_translate_4_by_6', .4, .6), ('random_translate_3_by_2', .3, .2),
      ('random_translate_tuple_factor', (.5, .4), (.2, .3)))
  def test_random_translation(self, height_factor, width_factor):
    self._run_test(height_factor, width_factor)

  def test_random_translation_negative_lower(self):
    mock_offset = np.random.random((12, 1))
    with test.mock.patch.object(
        gen_stateful_random_ops, 'stateful_uniform', return_value=mock_offset):
      with self.cached_session(use_gpu=True):
        layer = image_preprocessing.RandomTranslation((-0.2, .3), .4)
        layer_2 = image_preprocessing.RandomTranslation((0.2, .3), .4)
        inp = np.random.random((12, 5, 8, 3)).astype(np.float32)
        actual_output = layer(inp, training=1)
        actual_output_2 = layer_2(inp, training=1)
        self.assertAllClose(actual_output, actual_output_2)

  def test_random_translation_inference(self):
    with CustomObjectScope(
        {'RandomTranslation': image_preprocessing.RandomTranslation}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomTranslation(.5, .5)
        actual_output = layer(input_images, training=0)
        self.assertAllClose(expected_output, actual_output)

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomTranslation(.5, .6, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomTranslation.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomTransformTest(keras_parameterized.TestCase):

  def _run_random_transform_with_mock(self,
                                      transform_matrix,
                                      expected_output,
                                      mode,
                                      interpolation='bilinear'):
    inp = np.arange(15).reshape((1, 5, 3, 1)).astype(np.float32)
    with self.cached_session(use_gpu=True):
      output = image_preprocessing.transform(
          inp, transform_matrix, fill_mode=mode, interpolation=interpolation)
    self.assertAllClose(expected_output, output)

  def test_random_translation_reflect(self):
    # reflected output is (dcba|abcd|dcba)

    if compat.forward_compatible(2020, 3, 25):
      # Test down shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[0., 1., 2.],
           [0., 1., 2.],
           [3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., -1., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'reflect')

      # Test up shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11.],
           [12., 13., 14.],
           [12., 13., 14.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., 1., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'reflect')

      # Test left shift by 1.
      # reflected output is (dcba|abcd|dcba)
      # pyformat: disable
      expected_output = np.asarray(
          [[1., 2., 2.],
           [4., 5., 5.],
           [7., 8., 8.],
           [10., 11., 11.],
           [13., 14., 14.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'reflect')

      # Test right shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[0., 0., 1.],
           [3., 3., 4],
           [6., 6., 7.],
           [9., 9., 10.],
           [12., 12., 13.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., -1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'reflect')

  def test_random_translation_wrap(self):
    # warpped output is (abcd|abcd|abcd)

    if compat.forward_compatible(2020, 3, 25):
      # Test down shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[12., 13., 14.],
           [0., 1., 2.],
           [3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., -1., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'wrap')

      # Test up shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11.],
           [12., 13., 14.],
           [0., 1., 2.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., 1., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'wrap')

      # Test left shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[1., 2., 0.],
           [4., 5., 3.],
           [7., 8., 6.],
           [10., 11., 9.],
           [13., 14., 12.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'wrap')

      # Test right shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[2., 0., 1.],
           [5., 3., 4],
           [8., 6., 7.],
           [11., 9., 10.],
           [14., 12., 13.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., -1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'wrap')

  def test_random_translation_constant(self):
    # constant output is (0000|abcd|0000)

    if compat.forward_compatible(2020, 3, 25):
      # Test down shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[0., 0., 0.],
           [0., 1., 2.],
           [3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., -1., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'constant')

      # Test up shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11.],
           [12., 13., 14.],
           [0., 0., 0.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., 1., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'constant')

      # Test left shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[1., 2., 0.],
           [4., 5., 0.],
           [7., 8., 0.],
           [10., 11., 0.],
           [13., 14., 0.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'constant')

      # Test right shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[0., 0., 1.],
           [0., 3., 4],
           [0., 6., 7.],
           [0., 9., 10.],
           [0., 12., 13.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., -1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(transform_matrix, expected_output,
                                           'constant')

  def test_random_translation_nearest_interpolation(self):
    # nearest output is (aaaa|abcd|dddd)

    if compat.forward_compatible(2020, 3, 25):
      # Test down shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[0., 0., 0.],
           [0., 1., 2.],
           [3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., -1., 0., 0.]])
      self._run_random_transform_with_mock(
          transform_matrix, expected_output,
          mode='constant', interpolation='nearest')

      # Test up shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[3., 4., 5.],
           [6., 7., 8],
           [9., 10., 11.],
           [12., 13., 14.],
           [0., 0., 0.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 0., 0., 1., 1., 0., 0.]])
      self._run_random_transform_with_mock(
          transform_matrix, expected_output,
          mode='constant', interpolation='nearest')

      # Test left shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[1., 2., 0.],
           [4., 5., 0.],
           [7., 8., 0.],
           [10., 11., 0.],
           [13., 14., 0.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., 1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(
          transform_matrix, expected_output,
          mode='constant', interpolation='nearest')

      # Test right shift by 1.
      # pyformat: disable
      expected_output = np.asarray(
          [[0., 0., 1.],
           [0., 3., 4],
           [0., 6., 7.],
           [0., 9., 10.],
           [0., 12., 13.]]).reshape((1, 5, 3, 1)).astype(np.float32)
      # pyformat: enable
      transform_matrix = np.asarray([[1., 0., -1., 0., 1., 0., 0., 0.]])
      self._run_random_transform_with_mock(
          transform_matrix, expected_output,
          mode='constant', interpolation='nearest')


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomRotationTest(keras_parameterized.TestCase):

  def _run_test(self, factor):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    kwargs = {'factor': factor}
    with tf_test_util.use_gpu():
      testing_utils.layer_test(
          image_preprocessing.RandomRotation,
          kwargs=kwargs,
          input_shape=(num_samples, orig_height, orig_width, channels),
          expected_output_shape=(None, orig_height, orig_width, channels))

  @parameterized.named_parameters(('random_rotate_4', .4),
                                  ('random_rotate_3', .3),
                                  ('random_rotate_tuple_factor', (.5, .4)))
  def test_random_rotation(self, factor):
    self._run_test(factor)

  def test_random_rotation_inference(self):
    with CustomObjectScope(
        {'RandomTranslation': image_preprocessing.RandomRotation}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomRotation(.5)
        actual_output = layer(input_images, training=0)
        self.assertAllClose(expected_output, actual_output)

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomRotation(.5, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomRotation.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomZoomTest(keras_parameterized.TestCase):

  def _run_test(self, height_factor, width_factor):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    kwargs = {'height_factor': height_factor, 'width_factor': width_factor}
    with tf_test_util.use_gpu():
      testing_utils.layer_test(
          image_preprocessing.RandomZoom,
          kwargs=kwargs,
          input_shape=(num_samples, orig_height, orig_width, channels),
          expected_output_shape=(None, orig_height, orig_width, channels))

  @parameterized.named_parameters(
      ('random_zoom_4_by_6', .4, .6), ('random_zoom_2_by_3', .2, .3),
      ('random_zoom_tuple_factor', (.4, .5), (.2, .3)))
  def test_random_zoom_in(self, height_factor, width_factor):
    self._run_test(height_factor, width_factor)

  @parameterized.named_parameters(
      ('random_zoom_4_by_6', 1.4, 1.6), ('random_zoom_2_by_3', 1.2, 1.3),
      ('random_zoom_tuple_factor', (1.4, 1.5), (1.2, 1.3)))
  def test_random_zoom_out(self, height_factor, width_factor):
    self._run_test(height_factor, width_factor)

  def test_random_zoom_invalid_factor(self):
    with self.assertRaises(ValueError):
      image_preprocessing.RandomZoom((.5, .4), .2)
    with self.assertRaises(ValueError):
      image_preprocessing.RandomZoom(.2, (.5, .4))

  def test_random_zoom_inference(self):
    with CustomObjectScope(
        {'RandomZoom': image_preprocessing.RandomZoom}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomZoom(.5, .5)
        actual_output = layer(input_images, training=0)
        self.assertAllClose(expected_output, actual_output)

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomZoom(.5, .6, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomZoom.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomHeightTest(keras_parameterized.TestCase):

  def _run_test(self, factor):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    with tf_test_util.use_gpu():
      img = np.random.random((num_samples, orig_height, orig_width, channels))
      layer = image_preprocessing.RandomHeight(factor)
      img_out = layer(img, training=True)
      self.assertEqual(img_out.shape[0], 2)
      self.assertEqual(img_out.shape[2], 8)
      self.assertEqual(img_out.shape[3], 3)

  @parameterized.named_parameters(('random_height_4_by_6', (.4, .6)),
                                  ('random_height_3_by_2', (.3, 1.2)),
                                  ('random_height_3', .3))
  def test_random_height_basic(self, factor):
    self._run_test(factor)

  def test_valid_random_height(self):
    # need (maxval - minval) * rnd + minval = 0.6
    mock_factor = 0
    with test.mock.patch.object(
        gen_stateful_random_ops, 'stateful_uniform', return_value=mock_factor):
      with tf_test_util.use_gpu():
        img = np.random.random((12, 5, 8, 3))
        layer = image_preprocessing.RandomHeight(.4)
        img_out = layer(img, training=True)
        self.assertEqual(img_out.shape[1], 3)

  def test_random_height_invalid_factor(self):
    with self.assertRaises(ValueError):
      image_preprocessing.RandomHeight((-1.5, .4))

  def test_random_height_inference(self):
    with CustomObjectScope({'RandomHeight': image_preprocessing.RandomHeight}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomHeight(.5)
        actual_output = layer(input_images, training=0)
        self.assertAllClose(expected_output, actual_output)

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomHeight(.5, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomHeight.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
class RandomWidthTest(keras_parameterized.TestCase):

  def _run_test(self, factor):
    np.random.seed(1337)
    num_samples = 2
    orig_height = 5
    orig_width = 8
    channels = 3
    with tf_test_util.use_gpu():
      img = np.random.random((num_samples, orig_height, orig_width, channels))
      layer = image_preprocessing.RandomWidth(factor)
      img_out = layer(img, training=True)
      self.assertEqual(img_out.shape[0], 2)
      self.assertEqual(img_out.shape[1], 5)
      self.assertEqual(img_out.shape[3], 3)

  @parameterized.named_parameters(('random_width_4_by_6', (.4, .6)),
                                  ('random_width_3_by_2', (.3, 1.2)),
                                  ('random_width_3', .3))
  def test_random_width_basic(self, factor):
    self._run_test(factor)

  def test_valid_random_width(self):
    # need (maxval - minval) * rnd + minval = 0.6
    mock_factor = 0
    with test.mock.patch.object(
        gen_stateful_random_ops, 'stateful_uniform', return_value=mock_factor):
      with tf_test_util.use_gpu():
        img = np.random.random((12, 8, 5, 3))
        layer = image_preprocessing.RandomWidth(.4)
        img_out = layer(img, training=True)
        self.assertEqual(img_out.shape[2], 3)

  def test_random_width_invalid_factor(self):
    with self.assertRaises(ValueError):
      image_preprocessing.RandomWidth((-1.5, .4))

  def test_random_width_inference(self):
    with CustomObjectScope({'RandomWidth': image_preprocessing.RandomWidth}):
      input_images = np.random.random((2, 5, 8, 3)).astype(np.float32)
      expected_output = input_images
      with tf_test_util.use_gpu():
        layer = image_preprocessing.RandomWidth(.5)
        actual_output = layer(input_images, training=0)
        self.assertAllClose(expected_output, actual_output)

  @tf_test_util.run_v2_only
  def test_config_with_custom_name(self):
    layer = image_preprocessing.RandomWidth(.5, name='image_preproc')
    config = layer.get_config()
    layer_1 = image_preprocessing.RandomWidth.from_config(config)
    self.assertEqual(layer_1.name, layer.name)


if __name__ == '__main__':
  test.main()

numpy.asarray tensorflow.python.compat.compat.forward_compatible tensorflow.python.keras.utils.generic_utils.CustomObjectScope tensorflow.python.keras.layers.preprocessing.image_preprocessing.CenterCrop tensorflow.python.platform.test.is_built_with_rocm tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip.from_config numpy.mean tensorflow.python.keras.layers.preprocessing.image_preprocessing.Resizing tensorflow.python.ops.image_ops_impl.resize_images_v2 tensorflow.python.keras.layers.preprocessing.image_preprocessing.CenterCrop.from_config tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomRotation.from_config numpy.random.randint tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop numpy.reshape numpy.arange tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom.from_config tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop.from_config tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth tensorflow.python.keras.layers.preprocessing.image_preprocessing.transform tensorflow.python.keras.layers.preprocessing.image_preprocessing.Rescaling tensorflow.python.platform.test.main tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth.from_config tensorflow.python.keras.keras_parameterized.run_all_keras_modes tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast.from_config tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation.from_config tensorflow.python.keras.testing_utils.layer_test numpy.flip tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomRotation tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight.from_config tensorflow.python.keras.layers.preprocessing.image_preprocessing.Resizing.from_config numpy.random.random numpy.random.seed tensorflow.python.keras.layers.preprocessing.image_preprocessing.Rescaling.from_config tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom tensorflow.python.platform.test.mock.patch.object tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip tensorflow.python.framework.test_util.use_gpu tensorflow.python.ops.random_ops.random_uniform tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast
[(38, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (105, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (166, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (291, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (375, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (460, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (513, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (757, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (798, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (851, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (906, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (56, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('down_sample_bilinear_2_by_2', {'interpolation': 'bilinear'}, 2, 2)", "('down_sample_bilinear_3_by_2', {'interpolation': 'bilinear'}, 3, 2)", "('down_sample_nearest_2_by_2', {'interpolation': 'nearest'}, 2, 2)", "('down_sample_nearest_3_by_2', {'interpolation': 'nearest'}, 3, 2)", "('down_sample_area_2_by_2', {'interpolation': 'area'}, 2, 2)", "('down_sample_area_3_by_2', {'interpolation': 'area'}, 3, 2)"], {}), False, 'from absl.testing import parameterized\n'), (67, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('up_sample_bilinear_10_by_12', {'interpolation': 'bilinear'}, 10, 12)", "('up_sample_bilinear_12_by_12', {'interpolation': 'bilinear'}, 12, 12)", "('up_sample_nearest_10_by_12', {'interpolation': 'nearest'}, 10, 12)", "('up_sample_nearest_12_by_12', {'interpolation': 'nearest'}, 12, 12)", "('up_sample_area_10_by_12', {'interpolation': 'area'}, 10, 12)", "('up_sample_area_12_by_12', {'interpolation': 'area'}, 12, 12)"], {}), False, 'from absl.testing import parameterized\n'), (78, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('reshape_bilinear_10_by_4', {'interpolation': 'bilinear'}, 10, 4)"], {}), False, 'from absl.testing import parameterized\n'), (129, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('center_crop_3_by_4', 3, 4)", "('center_crop_3_by_2', 3, 2)"], {}), False, 'from absl.testing import parameterized\n'), (136, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('center_crop_4_by_5', 4, 5)", "('center_crop_4_by_3', 4, 3)"], {}), False, 'from absl.testing import parameterized\n'), (143, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('center_crop_4_by_6', 4, 6)", "('center_crop_3_by_2', 3, 2)"], {}), False, 'from absl.testing import parameterized\n'), (150, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('center_crop_5_by_12', 5, 12)", "('center_crop_10_by_8', 10, 8)", "('center_crop_10_by_12', 10, 12)"], {}), False, 'from absl.testing import parameterized\n'), (184, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_crop_5_by_12', 5, 12)", "('random_crop_10_by_8', 10, 8)", "('random_crop_10_by_12', 10, 12)"], {}), False, 'from absl.testing import parameterized\n'), (215, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_crop_4_by_6', 4, 6)", "('random_crop_3_by_2', 3, 2)"], {}), False, 'from absl.testing import parameterized\n'), (260, 'tensorflow.python.keras.keras_parameterized.run_all_keras_modes', 'keras_parameterized.run_all_keras_modes', ([], {'always_skip_v1': '(True)'}), False, 'from tensorflow.python.keras import keras_parameterized\n'), (317, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_flip_horizontal', 'horizontal')", "('random_flip_vertical', 'vertical')", "('random_flip_both', 'horizontal_and_vertical')"], {}), False, 'from absl.testing import parameterized\n'), (404, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_contrast_2_by_5', 0.2, 0.5)", "('random_contrast_2_by_13', 0.2, 1.3)", "('random_contrast_5_by_2', 0.5, 0.2)"], {}), False, 'from absl.testing import parameterized\n'), (413, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_contrast_amplitude_2', 0.2)", "('random_contrast_amplitude_5', 0.5)"], {}), False, 'from absl.testing import parameterized\n'), (477, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_translate_4_by_6', 0.4, 0.6)", "('random_translate_3_by_2', 0.3, 0.2)", "('random_translate_tuple_factor', (0.5, 0.4), (0.2, 0.3))"], {}), False, 'from absl.testing import parameterized\n'), (774, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_rotate_4', 0.4)", "('random_rotate_3', 0.3)", "('random_rotate_tuple_factor', (0.5, 0.4))"], {}), False, 'from absl.testing import parameterized\n'), (815, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_zoom_4_by_6', 0.4, 0.6)", "('random_zoom_2_by_3', 0.2, 0.3)", "('random_zoom_tuple_factor', (0.4, 0.5), (0.2, 0.3))"], {}), False, 'from absl.testing import parameterized\n'), (821, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_zoom_4_by_6', 1.4, 1.6)", "('random_zoom_2_by_3', 1.2, 1.3)", "('random_zoom_tuple_factor', (1.4, 1.5), (1.2, 1.3))"], {}), False, 'from absl.testing import parameterized\n'), (868, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_height_4_by_6', (0.4, 0.6))", "('random_height_3_by_2', (0.3, 1.2))", "('random_height_3', 0.3)"], {}), False, 'from absl.testing import parameterized\n'), (923, 'absl.testing.parameterized.named_parameters', 'parameterized.named_parameters', (["('random_width_4_by_6', (0.4, 0.6))", "('random_width_3_by_2', (0.3, 1.2))", "('random_width_3', 0.3)"], {}), False, 'from absl.testing import parameterized\n'), (962, 'tensorflow.python.platform.test.main', 'test.main', ([], {}), False, 'from tensorflow.python.platform import test\n'), (42, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (89, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Resizing', 'image_preprocessing.Resizing', (['(5)', '(5)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (91, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Resizing.from_config', 'image_preprocessing.Resizing.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (109, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (160, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.CenterCrop', 'image_preprocessing.CenterCrop', (['(5)', '(5)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (162, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.CenterCrop.from_config', 'image_preprocessing.CenterCrop.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (170, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (194, 'tensorflow.python.platform.test.is_built_with_rocm', 'test.is_built_with_rocm', ([], {}), False, 'from tensorflow.python.platform import test\n'), (199, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (201, 'numpy.random.randint', 'np.random.randint', ([], {'low': '(0)', 'high': '(3)'}), True, 'import numpy as np\n'), (202, 'numpy.random.randint', 'np.random.randint', ([], {'low': '(0)', 'high': '(5)'}), True, 'import numpy as np\n'), (219, 'tensorflow.python.platform.test.is_built_with_rocm', 'test.is_built_with_rocm', ([], {}), False, 'from tensorflow.python.platform import test\n'), (228, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (230, 'numpy.random.random', 'np.random.random', (['(12, 10, 6, 3)'], {}), True, 'import numpy as np\n'), (240, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (242, 'numpy.random.random', 'np.random.random', (['(12, 8, 16, 3)'], {}), True, 'import numpy as np\n'), (252, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop', 'image_preprocessing.RandomCrop', (['(5)', '(5)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (254, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop.from_config', 'image_preprocessing.RandomCrop.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (263, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.Rescaling'], {'kwargs': 'kwargs', 'input_shape': '(2, 5, 6, 3)', 'expected_output_shape': '(None, 5, 6, 3)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (271, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Rescaling', 'image_preprocessing.Rescaling', (['(0.004)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (272, 'tensorflow.python.ops.random_ops.random_uniform', 'random_ops.random_uniform', (['(2, 4, 5, 3)'], {}), False, 'from tensorflow.python.ops import random_ops\n'), (278, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Rescaling', 'image_preprocessing.Rescaling', (['(0.004)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (279, 'tensorflow.python.ops.random_ops.random_uniform', 'random_ops.random_uniform', (['(2, 4, 5, 3)', '(0)', '(100)'], {'dtype': '"""int32"""'}), False, 'from tensorflow.python.ops import random_ops\n'), (285, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Rescaling', 'image_preprocessing.Rescaling', (['(0.5)'], {'name': '"""rescaling"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (287, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Rescaling.from_config', 'image_preprocessing.Rescaling.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (295, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (303, 'numpy.random.random', 'np.random.random', (['(num_samples, orig_height, orig_width, channels)'], {}), True, 'import numpy as np\n'), (369, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip', 'image_preprocessing.RandomFlip', ([], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (371, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip.from_config', 'image_preprocessing.RandomFlip.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (383, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (390, 'numpy.random.random', 'np.random.random', (['(num_samples, orig_height, orig_width, channels)'], {}), True, 'import numpy as np\n'), (454, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(0.5, 0.6)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (456, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast.from_config', 'image_preprocessing.RandomContrast.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (464, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (484, 'numpy.random.random', 'np.random.random', (['(12, 1)'], {}), True, 'import numpy as np\n'), (507, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation', 'image_preprocessing.RandomTranslation', (['(0.5)', '(0.6)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (509, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation.from_config', 'image_preprocessing.RandomTranslation.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (530, 'tensorflow.python.compat.compat.forward_compatible', 'compat.forward_compatible', (['(2020)', '(3)', '(25)'], {}), False, 'from tensorflow.python.compat import compat\n'), (587, 'tensorflow.python.compat.compat.forward_compatible', 'compat.forward_compatible', (['(2020)', '(3)', '(25)'], {}), False, 'from tensorflow.python.compat import compat\n'), (643, 'tensorflow.python.compat.compat.forward_compatible', 'compat.forward_compatible', (['(2020)', '(3)', '(25)'], {}), False, 'from tensorflow.python.compat import compat\n'), (699, 'tensorflow.python.compat.compat.forward_compatible', 'compat.forward_compatible', (['(2020)', '(3)', '(25)'], {}), False, 'from tensorflow.python.compat import compat\n'), (761, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (792, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomRotation', 'image_preprocessing.RandomRotation', (['(0.5)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (794, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomRotation.from_config', 'image_preprocessing.RandomRotation.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (802, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (845, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom', 'image_preprocessing.RandomZoom', (['(0.5)', '(0.6)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (847, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom.from_config', 'image_preprocessing.RandomZoom.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (855, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (900, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight', 'image_preprocessing.RandomHeight', (['(0.5)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (902, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight.from_config', 'image_preprocessing.RandomHeight.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (910, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (955, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth', 'image_preprocessing.RandomWidth', (['(0.5)'], {'name': '"""image_preproc"""'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (957, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth.from_config', 'image_preprocessing.RandomWidth.from_config', (['config'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (48, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (49, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.Resizing'], {'kwargs': 'kwargs', 'input_shape': '(num_samples, orig_height, orig_width, channels)', 'expected_output_shape': '(None, expected_height, expected_width, channels)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (64, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'Resizing': image_preprocessing.Resizing}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (75, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'Resizing': image_preprocessing.Resizing}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (81, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'Resizing': image_preprocessing.Resizing}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (86, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.Resizing', 'image_preprocessing.Resizing', (['(5)', '(5)', '"""invalid_interpolation"""'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (119, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (120, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.CenterCrop'], {'kwargs': 'kwargs', 'input_shape': '(num_samples, orig_height, orig_width, channels)', 'input_data': 'input_images', 'expected_output': 'expected_output', 'expected_output_shape': '(None, expected_height, expected_width, channels)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (133, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'CenterCrop': image_preprocessing.CenterCrop}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (140, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'CenterCrop': image_preprocessing.CenterCrop}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (147, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'CenterCrop': image_preprocessing.CenterCrop}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (176, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (177, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.RandomCrop'], {'kwargs': 'kwargs', 'input_shape': '(num_samples, orig_height, orig_width, channels)', 'expected_output_shape': '(None, expected_height, expected_width, channels)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (204, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['stateless_random_ops', '"""stateless_random_uniform"""'], {'return_value': 'mock_offset'}), False, 'from tensorflow.python.platform import test\n'), (224, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomCrop': image_preprocessing.RandomCrop}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (231, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (232, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop', 'image_preprocessing.RandomCrop', (['height', 'width'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (234, 'tensorflow.python.ops.image_ops_impl.resize_images_v2', 'image_ops.resize_images_v2', (['inp'], {'size': '[5, 3]'}), True, 'from tensorflow.python.ops import image_ops_impl as image_ops\n'), (243, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (244, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop', 'image_preprocessing.RandomCrop', (['height', 'width'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (246, 'tensorflow.python.ops.image_ops_impl.resize_images_v2', 'image_ops.resize_images_v2', (['inp'], {'size': '[4, 8]'}), True, 'from tensorflow.python.ops import image_ops_impl as image_ops\n'), (302, 'numpy.reshape', 'np.reshape', (['mock_random', '[2, 1, 1, 1]'], {}), True, 'import numpy as np\n'), (310, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['random_ops', '"""random_uniform"""'], {'return_value': 'mock_random'}), False, 'from tensorflow.python.platform import test\n'), (322, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomFlip': image_preprocessing.RandomFlip}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (326, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomFlip': image_preprocessing.RandomFlip}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (327, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (329, 'numpy.reshape', 'np.reshape', (['mock_random', '[2, 1, 1, 1]'], {}), True, 'import numpy as np\n'), (332, 'numpy.flip', 'np.flip', (['input_images[(0), :, :, :]'], {'axis': '(0)'}), True, 'import numpy as np\n'), (336, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomFlip': image_preprocessing.RandomFlip}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (337, 'numpy.random.seed', 'np.random.seed', (['(1337)'], {}), True, 'import numpy as np\n'), (339, 'numpy.reshape', 'np.reshape', (['mock_random', '[2, 1, 1, 1]'], {}), True, 'import numpy as np\n'), (342, 'numpy.flip', 'np.flip', (['input_images[(0), :, :, :]'], {'axis': '(1)'}), True, 'import numpy as np\n'), (346, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomFlip': image_preprocessing.RandomFlip}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (355, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomFlip': image_preprocessing.RandomFlip}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (359, 'numpy.reshape', 'np.reshape', (['mock_random', '[2, 1, 1, 1]'], {}), True, 'import numpy as np\n'), (393, 'numpy.mean', 'np.mean', (['inp'], {'axis': '(1)', 'keepdims': '(True)'}), True, 'import numpy as np\n'), (395, 'numpy.mean', 'np.mean', (['inp_mean'], {'axis': '(2)', 'keepdims': '(True)'}), True, 'import numpy as np\n'), (397, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['random_ops', '"""random_uniform"""'], {'return_value': 'mock_random'}), False, 'from tensorflow.python.platform import test\n'), (409, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomContrast': image_preprocessing.RandomContrast}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (417, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomContrast': image_preprocessing.RandomContrast}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (419, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (425, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomContrast': image_preprocessing.RandomContrast}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (435, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomContrast': image_preprocessing.RandomContrast}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (437, 'numpy.random.randint', 'np.random.randint', ([], {'low': '(0)', 'high': '(255)', 'size': '(2, 5, 8, 3)'}), True, 'import numpy as np\n'), (444, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(-0.1, 0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (447, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(1.1, 0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (450, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(0.1, -0.2)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (470, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (471, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.RandomTranslation'], {'kwargs': 'kwargs', 'input_shape': '(num_samples, orig_height, orig_width, channels)', 'expected_output_shape': '(None, orig_height, orig_width, channels)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (485, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['gen_stateful_random_ops', '"""stateful_uniform"""'], {'return_value': 'mock_offset'}), False, 'from tensorflow.python.platform import test\n'), (496, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomTranslation': image_preprocessing.RandomTranslation}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (523, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.transform', 'image_preprocessing.transform', (['inp', 'transform_matrix'], {'fill_mode': 'mode', 'interpolation': 'interpolation'}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (540, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (553, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (567, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (580, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (597, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (610, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (623, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (636, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (653, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (666, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (679, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (692, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (709, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (723, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (737, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (751, 'numpy.asarray', 'np.asarray', (['[[1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (767, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (768, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.RandomRotation'], {'kwargs': 'kwargs', 'input_shape': '(num_samples, orig_height, orig_width, channels)', 'expected_output_shape': '(None, orig_height, orig_width, channels)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (781, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomTranslation': image_preprocessing.RandomRotation}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (808, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (809, 'tensorflow.python.keras.testing_utils.layer_test', 'testing_utils.layer_test', (['image_preprocessing.RandomZoom'], {'kwargs': 'kwargs', 'input_shape': '(num_samples, orig_height, orig_width, channels)', 'expected_output_shape': '(None, orig_height, orig_width, channels)'}), False, 'from tensorflow.python.keras import testing_utils\n'), (829, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom', 'image_preprocessing.RandomZoom', (['(0.5, 0.4)', '(0.2)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (831, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom', 'image_preprocessing.RandomZoom', (['(0.2)', '(0.5, 0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (834, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomZoom': image_preprocessing.RandomZoom}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (860, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (861, 'numpy.random.random', 'np.random.random', (['(num_samples, orig_height, orig_width, channels)'], {}), True, 'import numpy as np\n'), (862, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight', 'image_preprocessing.RandomHeight', (['factor'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (877, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['gen_stateful_random_ops', '"""stateful_uniform"""'], {'return_value': 'mock_factor'}), False, 'from tensorflow.python.platform import test\n'), (887, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight', 'image_preprocessing.RandomHeight', (['(-1.5, 0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (890, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomHeight': image_preprocessing.RandomHeight}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (915, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (916, 'numpy.random.random', 'np.random.random', (['(num_samples, orig_height, orig_width, channels)'], {}), True, 'import numpy as np\n'), (917, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth', 'image_preprocessing.RandomWidth', (['factor'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (932, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['gen_stateful_random_ops', '"""stateful_uniform"""'], {'return_value': 'mock_factor'}), False, 'from tensorflow.python.platform import test\n'), (942, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth', 'image_preprocessing.RandomWidth', (['(-1.5, 0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (945, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomWidth': image_preprocessing.RandomWidth}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (115, 'numpy.random.random', 'np.random.random', (['(num_samples, orig_height, orig_width, channels)'], {}), True, 'import numpy as np\n'), (190, 'tensorflow.python.keras.utils.generic_utils.CustomObjectScope', 'CustomObjectScope', (["{'RandomCrop': image_preprocessing.RandomCrop}"], {}), False, 'from tensorflow.python.keras.utils.generic_utils import CustomObjectScope\n'), (207, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (208, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomCrop', 'image_preprocessing.RandomCrop', (['height', 'width'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (209, 'numpy.random.random', 'np.random.random', (['(12, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (307, 'numpy.flip', 'np.flip', (['expected_output'], {'axis': '(1)'}), True, 'import numpy as np\n'), (309, 'numpy.flip', 'np.flip', (['expected_output'], {'axis': '(2)'}), True, 'import numpy as np\n'), (312, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (313, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip', 'image_preprocessing.RandomFlip', (['mode'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (349, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (350, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip', 'image_preprocessing.RandomFlip', ([], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (357, 'numpy.flip', 'np.flip', (['input_images'], {'axis': '(1)'}), True, 'import numpy as np\n'), (360, 'tensorflow.python.platform.test.mock.patch.object', 'test.mock.patch.object', (['random_ops', '"""random_uniform"""'], {'return_value': 'mock_random'}), False, 'from tensorflow.python.platform import test\n'), (399, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (400, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(lower, upper)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (420, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (421, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['amplitude'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (429, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (430, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(0.1, 0.2)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (438, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (439, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomContrast', 'image_preprocessing.RandomContrast', (['(0.1, 0.2)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (488, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation', 'image_preprocessing.RandomTranslation', (['(-0.2, 0.3)', '(0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (489, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation', 'image_preprocessing.RandomTranslation', (['(0.2, 0.3)', '(0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (500, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (501, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomTranslation', 'image_preprocessing.RandomTranslation', (['(0.5)', '(0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (785, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (786, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomRotation', 'image_preprocessing.RandomRotation', (['(0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (838, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (839, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomZoom', 'image_preprocessing.RandomZoom', (['(0.5)', '(0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (879, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (880, 'numpy.random.random', 'np.random.random', (['(12, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (881, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight', 'image_preprocessing.RandomHeight', (['(0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (893, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (894, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomHeight', 'image_preprocessing.RandomHeight', (['(0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (934, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (935, 'numpy.random.random', 'np.random.random', (['(12, 8, 5, 3)'], {}), True, 'import numpy as np\n'), (936, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth', 'image_preprocessing.RandomWidth', (['(0.4)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (948, 'tensorflow.python.framework.test_util.use_gpu', 'tf_test_util.use_gpu', ([], {}), True, 'from tensorflow.python.framework import test_util as tf_test_util\n'), (949, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomWidth', 'image_preprocessing.RandomWidth', (['(0.5)'], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (330, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (340, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (347, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (356, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (363, 'tensorflow.python.keras.layers.preprocessing.image_preprocessing.RandomFlip', 'image_preprocessing.RandomFlip', ([], {}), False, 'from tensorflow.python.keras.layers.preprocessing import image_preprocessing\n'), (427, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (498, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (783, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (836, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (891, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (946, 'numpy.random.random', 'np.random.random', (['(2, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (490, 'numpy.random.random', 'np.random.random', (['(12, 5, 8, 3)'], {}), True, 'import numpy as np\n'), (521, 'numpy.arange', 'np.arange', (['(15)'], {}), True, 'import numpy as np\n'), (533, 'numpy.asarray', 'np.asarray', (['[[0.0, 1.0, 2.0], [0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, \n    10.0, 11]]'], {}), True, 'import numpy as np\n'), (546, 'numpy.asarray', 'np.asarray', (['[[3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, 10.0, 11.0], [12.0, 13.0, 14.0], [\n    12.0, 13.0, 14.0]]'], {}), True, 'import numpy as np\n'), (560, 'numpy.asarray', 'np.asarray', (['[[1.0, 2.0, 2.0], [4.0, 5.0, 5.0], [7.0, 8.0, 8.0], [10.0, 11.0, 11.0], [\n    13.0, 14.0, 14.0]]'], {}), True, 'import numpy as np\n'), (573, 'numpy.asarray', 'np.asarray', (['[[0.0, 0.0, 1.0], [3.0, 3.0, 4], [6.0, 6.0, 7.0], [9.0, 9.0, 10.0], [12.0, \n    12.0, 13.0]]'], {}), True, 'import numpy as np\n'), (590, 'numpy.asarray', 'np.asarray', (['[[12.0, 13.0, 14.0], [0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0,\n    10.0, 11]]'], {}), True, 'import numpy as np\n'), (603, 'numpy.asarray', 'np.asarray', (['[[3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, 10.0, 11.0], [12.0, 13.0, 14.0], [\n    0.0, 1.0, 2.0]]'], {}), True, 'import numpy as np\n'), (616, 'numpy.asarray', 'np.asarray', (['[[1.0, 2.0, 0.0], [4.0, 5.0, 3.0], [7.0, 8.0, 6.0], [10.0, 11.0, 9.0], [\n    13.0, 14.0, 12.0]]'], {}), True, 'import numpy as np\n'), (629, 'numpy.asarray', 'np.asarray', (['[[2.0, 0.0, 1.0], [5.0, 3.0, 4], [8.0, 6.0, 7.0], [11.0, 9.0, 10.0], [14.0,\n    12.0, 13.0]]'], {}), True, 'import numpy as np\n'), (646, 'numpy.asarray', 'np.asarray', (['[[0.0, 0.0, 0.0], [0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, \n    10.0, 11]]'], {}), True, 'import numpy as np\n'), (659, 'numpy.asarray', 'np.asarray', (['[[3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, 10.0, 11.0], [12.0, 13.0, 14.0], [\n    0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (672, 'numpy.asarray', 'np.asarray', (['[[1.0, 2.0, 0.0], [4.0, 5.0, 0.0], [7.0, 8.0, 0.0], [10.0, 11.0, 0.0], [\n    13.0, 14.0, 0.0]]'], {}), True, 'import numpy as np\n'), (685, 'numpy.asarray', 'np.asarray', (['[[0.0, 0.0, 1.0], [0.0, 3.0, 4], [0.0, 6.0, 7.0], [0.0, 9.0, 10.0], [0.0, \n    12.0, 13.0]]'], {}), True, 'import numpy as np\n'), (702, 'numpy.asarray', 'np.asarray', (['[[0.0, 0.0, 0.0], [0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, \n    10.0, 11]]'], {}), True, 'import numpy as np\n'), (716, 'numpy.asarray', 'np.asarray', (['[[3.0, 4.0, 5.0], [6.0, 7.0, 8], [9.0, 10.0, 11.0], [12.0, 13.0, 14.0], [\n    0.0, 0.0, 0.0]]'], {}), True, 'import numpy as np\n'), (730, 'numpy.asarray', 'np.asarray', (['[[1.0, 2.0, 0.0], [4.0, 5.0, 0.0], [7.0, 8.0, 0.0], [10.0, 11.0, 0.0], [\n    13.0, 14.0, 0.0]]'], {}), True, 'import numpy as np\n'), (744, 'numpy.asarray', 'np.asarray', (['[[0.0, 0.0, 1.0], [0.0, 3.0, 4], [0.0, 6.0, 7.0], [0.0, 9.0, 10.0], [0.0, \n    12.0, 13.0]]'], {}), True, 'import numpy as np\n')]