code: def infer_spatial_rank(input_tensor):
      """
      e.g. given an input tensor [Batch, X, Y, Z, Feature] the spatial rank is 3
      """
      input_shape = input_tensor.shape
      input_shape.with_rank_at_least(3)
      # dims = input_tensor.get_shape().ndims - 2
      # assert dims > 0, "input tensor should have at least one spatial dim, " \
      #                 "in addition to batch and channel dims"
      return int(input_shape.ndims - 2)
  
imports: from __future__ import absolute_import, print_function
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: infer_spatial_rank(input_tensor) and returns: int