class_docstr: resample inputs according to ``sample_coords``
class_docstr_tok: ["resample","inputs","according","to","``","sample_coords","``"]
code: def _resample_bspline(self, inputs, sample_coords):
      assert (
          inputs.shape.is_fully_defined()
      ), "input shape should be fully defined for bspline interpolation"
      in_size = inputs.shape.as_list()
      batch_size = in_size[0]
      in_spatial_size = in_size[1:-1]
      in_spatial_rank = infer_spatial_rank(inputs)
  
      out_spatial_rank = infer_spatial_rank(sample_coords)
      if in_spatial_rank == 2:
          raise NotImplementedError(
              "bspline interpolation not implemented for 2d yet"
          )
      assert batch_size == int(sample_coords.get_shape()[0])
      floor_coords = tf.floor(sample_coords)
  
      # Compute voxels to use for interpolation
      grid = tf.meshgrid(
          [-1.0, 0.0, 1.0, 2.0],
          [-1.0, 0.0, 1.0, 2.0],
          [-1.0, 0.0, 1.0, 2.0],
          indexing="ij",
      )
      offset_shape = (
          [1, -1] + [1] * out_spatial_rank + [in_spatial_rank]
      )
      offsets = tf.reshape(tf.stack(grid, 3), offset_shape)
      spatial_coords = offsets + tf.expand_dims(floor_coords, 1)
      spatial_coords = self.boundary_func(
          spatial_coords, in_spatial_size
      )
      spatial_coords = tf.cast(spatial_coords, COORDINATES_TYPE)
      knot_size = spatial_coords.shape.as_list()
  
      # Compute weights for each voxel
      def build_coef(u, d):
          coeff_list = [
              tf.pow(1 - u, 3),
              3 * tf.pow(u, 3) - 6 * tf.pow(u, 2) + 4,
              -3 * tf.pow(u, 3) + 3 * tf.pow(u, 2) + 3 * u + 1,
              tf.pow(u, 3),
          ]
          return tf.concat(coeff_list, d) / 6
  
      weight = tf.reshape(
          sample_coords - floor_coords, [batch_size, -1, 3]
      )
      coef_shape = [batch_size, 1, 1, 1, -1]
      Bu = build_coef(tf.reshape(weight[:, :, 0], coef_shape), 1)
      Bv = build_coef(tf.reshape(weight[:, :, 1], coef_shape), 2)
      Bw = build_coef(tf.reshape(weight[:, :, 2], coef_shape), 3)
      all_weights = tf.reshape(
          Bu * Bv * Bw, [batch_size] + knot_size[1:-1] + [1]
      )
  
      # Gather voxel values and compute weighted sum
      batch_coords = tf.reshape(
          tf.range(batch_size),
          [batch_size] + [1] * (len(knot_size) - 1),
      )
      batch_coords = tf.tile(batch_coords, [1] + knot_size[1:-1] + [1])
      raw_samples = tf.gather_nd(
          inputs, tf.concat([batch_coords, spatial_coords], -1)
      )
      return tf.reduce_sum(
          all_weights * raw_samples, reduction_indices=1
      )
  
file_path: NiftyNet/niftynet/layer/resampler.py
imports: from __future__ import absolute_import, division, print_function
  import tensorflow
  from niftynet.layer.base_layer import Layer
  from niftynet.layer.layer_util import infer_spatial_rank
  from niftynet.utilities.util_common import look_up_operations
label_desc: Use image node_id 5 for calling the ResamplerLayer obj's underlying member method code with example usage: obj._resample_bspline(inputs, sample_coords) and returns: tf, unknown