code: def test_gradient_correctness(self):
      if not resampler_module.HAS_NIFTYREG_RESAMPLING:
          self.skipTest(
              "Using native NiftyNet resampler; skipping test"
          )
          return
  
      for inter in ("LINEAR", "BSPLINE"):
          for b in ("ZERO", "REPLICATE", "SYMMETRIC"):
              for use_gpu in self._get_devs():
                  inputs = (
                      (
                          self.get_3d_input1(as_tensor=False),
                          [
                              [[-5.2, 0.25, 0.25], [0.25, 0.95, 0.25]],
                              [[0.75, 0.25, 0.25], [0.25, 0.25, 0.75]],
                          ],
                      ),
                      (
                          self.get_2d_input(as_tensor=False),
                          [
                              [[0.25, 0.25], [0.25, 0.78]],
                              [[0.62, 0.25], [0.25, 0.28]],
                          ],
                      ),
                  )
  
                  for np_img, np_u in inputs:
                      with self.session(use_gpu=use_gpu):
                          np_u = np.array(np_u)
  
                          while len(np_u.shape) < len(np_img.shape):
                              np_u = np.expand_dims(np_u, axis=2)
  
                          img = tf.constant(np_img, dtype=tf.float32)
                          disp = tf.constant(np_u, dtype=tf.float32)
  
                          # multimodal needs addressing
                          if img.shape.as_list()[-1] > 1:
                              img = tf.reshape(
                                  img[..., 0],
                                  img.shape.as_list()[:-1] + [1],
                              )
  
                          warped = ResamplerOptionalNiftyRegLayer(
                              interpolation=inter, boundary=b
                          )
                          warped = warped(img, disp)
                          # warped = tf.reduce_sum(warped)
  
                          tgrad, refgrad = tft.compute_gradient(
                              disp, disp.shape, warped, warped.shape
                          )
  
                          error = np.power(tgrad - refgrad, 2).sum()
                          refmag = np.power(refgrad, 2).sum()
  
                          self.assertLessEqual(error, 1e-2 * refmag)
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  import tensorflow.test
  from niftynet.contrib.layer.resampler_optional_niftyreg import ResamplerOptionalNiftyRegLayer
  from tests.niftynet_testcase import NiftyNetTestCase
  import niftynet.contrib.layer.resampler_optional_niftyreg
label_desc: Use image node_id 7 for calling the ResamplerTest obj's underlying member method code with example usage: obj.test_gradient_correctness() without return types