class_docstr: resample inputs according to ``sample_coords``
class_docstr_tok: ["resample","inputs","according","to","``","sample_coords","``"]
code: def _resample_nearest(self, inputs, sample_coords):
      # This is forward only as no gradient for tf.round
  
      # read input shape
      in_size = inputs.shape
      partial_shape = not in_size.is_fully_defined()
      in_spatial_size = None
  
      try:
          batch_size = int(in_size[0])
          n_coords = int(sample_coords.shape[0])
      except (TypeError, AssertionError, ValueError):
          tf.logging.fatal(
              "Unknown input shape, at least batch size "
              "and rank of the inputs are required."
          )
          raise
  
      # quantise coordinates
      spatial_coords = tf.round(sample_coords)
      if not partial_shape:
          in_spatial_size = in_size.as_list()[1:-1]
          spatial_coords = self.boundary_func(
              spatial_coords, in_spatial_size
          )
      spatial_coords = tf.cast(spatial_coords, COORDINATES_TYPE)
  
      if batch_size == n_coords:
          batch_inputs = tf.unstack(inputs)
          batch_coords = tf.unstack(spatial_coords)
          gathered_image = [
              tf.gather_nd(img, coord)
              for (img, coord) in zip(batch_inputs, batch_coords)
          ]
      elif n_coords == 1 and batch_size > 1:
          gathered_image = [
              tf.gather_nd(img, spatial_coords[0])
              for img in tf.unstack(inputs)
          ]
      else:
          raise NotImplementedError
      output = tf.stack(gathered_image, axis=0)
  
      if self.boundary == "ZERO" and in_spatial_size:
          scale = 1.0 / (
              tf.constant(in_spatial_size, dtype=tf.float32) - 1.0
          )
          mask = tf.logical_and(
              tf.reduce_all(sample_coords > 0, -1, True),
              tf.reduce_all(scale * sample_coords < 1, -1, True),
          )
          return output * tf.to_float(mask)
      return output
  
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 3 for calling the ResamplerLayer obj's underlying member method code with example usage: obj._resample_nearest(inputs, sample_coords) and returns: output, unknown