code: def spatial_to_seq(image_tensor: torch.Tensor):
      """
      Takes a torch tensor of shape (batch_size, channels, height, width)
      as used and outputted by CNNs and creates a sequence view of shape
      (sequence_length, batch_size, channels) as required by
      torch's transformer module. In other words, unrolls the
      spatial grid into the sequence length and rearranges the
      dimension ordering.
  
      Args:
          image_tensor: tensor of shape (batch_size, channels, height, width) (required).
      """
      original_size = image_tensor.size()
  
      batch_size = original_size[SPATIAL_BATCH_DIMENSION]
      num_channels = original_size[SPATIAL_CHANNEL_DIMENSION]
      spatial_height = original_size[SPATIAL_HEIGHT_DIMENSION]
      spatial_width = original_size[SPATIAL_WIDTH_DIMENSION]
  
      permuted_tensor = image_tensor.permute(
          SPATIAL_HEIGHT_DIMENSION,
          SPATIAL_WIDTH_DIMENSION,
          SPATIAL_BATCH_DIMENSION,
          SPATIAL_CHANNEL_DIMENSION,
      )
  
      sequence_tensor = permuted_tensor.view(
          spatial_height * spatial_width, batch_size, num_channels
      )
  
      return sequence_tensor
  
label_desc: Use image node_id 1 for calling a global function with example usage: spatial_to_seq(image_tensor) and returns: sequence_tensor