code: def _test_grads_images(
      self, interpolation="linear", boundary="replicate", ndim=2
  ):
      if ndim == 2:
          test_image, input_shape = get_multiple_2d_images()
          test_target, target_shape = get_multiple_2d_targets()
          identity_affine = [[1.0, 0.0, 0.0, 0.0, 1.0, 0.0]] * 4
      else:
          test_image, input_shape = get_multiple_3d_images()
          test_target, target_shape = get_multiple_3d_targets()
          identity_affine = [
              [
                  1.0,
                  0.0,
                  0.0,
                  0.0,
                  1.0,
                  0.0,
                  1.0,
                  0.0,
                  0.0,
                  0.0,
                  1.0,
                  0.0,
              ]
          ] * 4
      affine_var = tf.get_variable(
          "affine", initializer=identity_affine
      )
      grid = AffineGridWarperLayer(
          source_shape=input_shape[1:-1],
          output_shape=target_shape[1:-1],
          constraints=None,
      )
      warp_coords = grid(affine_var)
      resampler = ResamplerLayer(interpolation, boundary=boundary)
      new_image = resampler(
          tf.constant(test_image, dtype=tf.float32), warp_coords
      )
  
      diff = tf.reduce_mean(
          tf.squared_difference(
              new_image, tf.constant(test_target, dtype=tf.float32)
          )
      )
      optimiser = tf.train.AdagradOptimizer(0.01)
      grads = optimiser.compute_gradients(diff)
      opt = optimiser.apply_gradients(grads)
      with self.cached_session() as sess:
          sess.run(tf.global_variables_initializer())
          init_val, affine_val = sess.run([diff, affine_var])
          for _ in range(5):
              _, diff_val, affine_val = sess.run(
                  [opt, diff, affine_var]
              )
              print("{}, {}".format(diff_val, affine_val[0]))
          self.assertGreater(init_val, diff_val)
  
imports: from __future__ import absolute_import, print_function, division
  import base64
  import numpy
  import tensorflow
  from niftynet.layer.grid_warper import AffineGridWarperLayer
  from niftynet.layer.resampler import ResamplerLayer
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 1 for calling the image_test obj's underlying member method code with example usage: obj._test_grads_images(interpolation, boundary, ndim) without return types