class_docstr: Unit test for GPUImageResampling defined in python_wrapper.cpp
class_docstr_tok: ["Unit","test","for","GPUImageResampling","defined","in","python_wrapper.cpp"]
code: def _test_resampling(self, use_gpu):
      for floating in self._get_images():
          floating_data = floating.get_data()
          nof_dims = len(floating_data.shape)
  
          transposed_shape = list(floating_data.shape)
          transposed_shape.reverse()
          image_batch_shape = [1] * 2 + transposed_shape
          disp_batch_shape = [1] + [nof_dims] + transposed_shape
  
          for inter in (0, 1, 3):
              with self.session(use_gpu=use_gpu) as sess:
                  img = tf.placeholder(
                      tf.float32, shape=image_batch_shape
                  )
                  disp = tf.placeholder(
                      tf.float32, shape=disp_batch_shape
                  )
  
                  warped = res.niftyreg_image_resampling(
                      img, disp, interpolation=inter
                  )
  
                  for u in (0.5001, 3.50001):
                      for d in range(nof_dims):
                          displacement_data = (
                              self._make_constant_displacement_image(
                                  u, d, floating_data
                              )
                          )
  
                          # NiftyReg expects displacement components to be
                          # indexed w/ slowest index
                          def _transpose(data):
                              return np.transpose(
                                  data,
                                  range(len(data.shape) - 1, -1, -1),
                              )
  
                          resampled_data = sess.run(
                              warped,
                              feed_dict={
                                  img: _transpose(
                                      floating_data
                                  ).reshape(image_batch_shape),
                                  disp: _transpose(
                                      displacement_data
                                  ).reshape(disp_batch_shape),
                              },
                          )
  
                          resampled_data = _transpose(
                              resampled_data
                          ).reshape(floating_data.shape)
  
                          self._test_resampled(
                              resampled_data, floating_data, u, inter, d
                          )
  
file_path: NiftyNet/niftynet/contrib/niftyreg_image_resampling/tests/test_resampler.py
imports: from glob import glob
  import math
  import os.path
  import nibabel
  import numpy
  import copy
  import tensorflow
  import tensorflow.test
  from niftynet.contrib.niftyreg_image_resampling.niftyreg_module_loader import get_niftyreg_module
label_desc: Use image node_id 5 for calling the ResamplerTest obj's underlying member method code with example usage: obj._test_resampling(use_gpu) and returns: np