code: def _transform_thin_plate_spline(
      dest_offsets,
      input,
      right_mat,
      L_inv,
      source_points,
      out_height,
      out_width,
      precompute_grid,
      downsample_factor,
      border_mode,
  ):
      num_batch, num_channels, height, width = input.shape
      num_control_points = source_points.shape[1]
  
      # reshape destination offsets to be (num_batch, 2, num_control_points)
      # and add to source_points
      dest_points = source_points + T.reshape(
          dest_offsets, (num_batch, 2, num_control_points)
      )
  
      # Solve as in ref [2]
      coefficients = T.dot(dest_points, L_inv[:, 3:].T)
  
      if precompute_grid:
          # Transform each point on the source grid (image_size x image_size)
          right_mat = T.tile(
              right_mat.dimshuffle("x", 0, 1), (num_batch, 1, 1)
          )
          transformed_points = T.batched_dot(coefficients, right_mat)
  
      else:
          # Transformed grid
          out_height = T.cast(height // downsample_factor[0], "int64")
          out_width = T.cast(width // downsample_factor[1], "int64")
          orig_grid = _meshgrid(out_height, out_width)
          orig_grid = orig_grid[0:2, :]
          orig_grid = T.tile(orig_grid, (num_batch, 1, 1))
  
          # Transform each point on the source grid (image_size x image_size)
          transformed_points = _get_transformed_points_tps(
              orig_grid,
              source_points,
              coefficients,
              num_control_points,
              num_batch,
          )
  
      # Get out new points
      x_transformed = transformed_points[:, 0].flatten()
      y_transformed = transformed_points[:, 1].flatten()
  
      # dimshuffle input to  (bs, height, width, channels)
      input_dim = input.dimshuffle(0, 2, 3, 1)
      input_transformed = _interpolate(
          input_dim,
          x_transformed,
          y_transformed,
          out_height,
          out_width,
          border_mode,
      )
  
      output = T.reshape(
          input_transformed,
          (num_batch, out_height, out_width, num_channels),
      )
      output = output.dimshuffle(
          0, 3, 1, 2
      )  # dimshuffle to conv format
      return output
  
imports: import theano
  import theano.tensor
  import numpy
  from ..None import init
  from ..None import nonlinearities
  from ..utils import as_tuple, floatX, int_types
  from ..random import get_rng
  from .base import Layer, MergeLayer
  from theano.sandbox.rng_mrg import MRG_RandomStreams
label_desc: Use image node_id 6 for calling a global function with example usage: _transform_thin_plate_spline(dest_offsets, input, right_mat, L_inv, source_points, out_height, out_width, precompute_grid, downsample_factor, border_mode) and returns: output