code: def test_affine_transform(
      self, interpolation, fill_mode, data_format
  ):
      if backend.backend() == "tensorflow" and fill_mode == "mirror":
          self.skipTest(
              "In tensorflow backend, applying affine_transform with "
              "fill_mode=mirror is not supported"
          )
      if backend.backend() == "tensorflow" and fill_mode == "wrap":
          self.skipTest(
              "In tensorflow backend, the numerical results of applying "
              "affine_transform with fill_mode=wrap is inconsistent with"
              "scipy"
          )
      # TODO: `nearest` interpolation in jax and torch causes random index
      # shifting, resulting in significant differences in output which leads
      # to failure
      if (
          backend.backend() in ("jax", "torch")
          and interpolation == "nearest"
      ):
          self.skipTest(
              f"In {backend.backend()} backend, "
              f"interpolation={interpolation} causes index shifting and "
              "leads test failure"
          )
  
      # Unbatched case
      if data_format == "channels_first":
          x = np.random.random((3, 50, 50)).astype("float32") * 255
      else:
          x = np.random.random((50, 50, 3)).astype("float32") * 255
      transform = np.random.random(size=(6)).astype("float32")
      transform = np.pad(transform, (0, 2))  # makes c0, c1 always 0
      out = kimage.affine_transform(
          x,
          transform,
          interpolation=interpolation,
          fill_mode=fill_mode,
          data_format=data_format,
      )
      if data_format == "channels_first":
          x = np.transpose(x, (1, 2, 0))
      coordinates = _compute_affine_transform_coordinates(x, transform)
      ref_out = _fixed_map_coordinates(
          x,
          coordinates,
          order=AFFINE_TRANSFORM_INTERPOLATIONS[interpolation],
          fill_mode=fill_mode,
      )
      if data_format == "channels_first":
          ref_out = np.transpose(ref_out, (2, 0, 1))
      self.assertEqual(tuple(out.shape), tuple(ref_out.shape))
      self.assertAllClose(ref_out, out, atol=1e-3, rtol=1e-3)
  
      # Batched case
      if data_format == "channels_first":
          x = np.random.random((2, 3, 50, 50)).astype("float32") * 255
      else:
          x = np.random.random((2, 50, 50, 3)).astype("float32") * 255
      transform = np.random.random(size=(2, 6)).astype("float32")
      transform = np.pad(
          transform, [(0, 0), (0, 2)]
      )  # makes c0, c1 always 0
      out = kimage.affine_transform(
          x,
          transform,
          interpolation=interpolation,
          fill_mode=fill_mode,
          data_format=data_format,
      )
      if data_format == "channels_first":
          x = np.transpose(x, (0, 2, 3, 1))
      coordinates = _compute_affine_transform_coordinates(x, transform)
      ref_out = np.stack(
          [
              _fixed_map_coordinates(
                  x[i],
                  coordinates[i],
                  order=AFFINE_TRANSFORM_INTERPOLATIONS[interpolation],
                  fill_mode=fill_mode,
              )
              for i in range(x.shape[0])
          ],
          axis=0,
      )
      if data_format == "channels_first":
          ref_out = np.transpose(ref_out, (0, 3, 1, 2))
      self.assertEqual(tuple(out.shape), tuple(ref_out.shape))
      self.assertAllClose(ref_out, out, atol=1e-3, rtol=1e-3)
  
imports: import math
  import numpy
  import pytest
  import scipy.ndimage
  import tensorflow
  from absl.testing import parameterized
  from keras import backend
  from keras import testing
  from keras.backend.common.keras_tensor import KerasTensor
  from keras.ops import image
label_desc: Use image node_id 2 for calling the ImageOpsCorrectnessTest obj's underlying member method code with example usage: obj.test_affine_transform(interpolation, fill_mode, data_format) without return types