code: def nested_tensor_from_tensor_list(
      tensor_list: Union[List, "torch.Tensor"]
  ):
      """
      Adapted from DETR source: https://github.com/facebookresearch/detr
      (detr/util/misc.py)
      """
  
      if tensor_list[0].ndim == 3:
          img_shape_list = [list(img.shape) for img in tensor_list]
          max_size = img_shape_list[0]
          for sublist in img_shape_list[1:]:
              for index, item in enumerate(sublist):
                  max_size[index] = max(max_size[index], item)
          batch_shape = [len(tensor_list)] + max_size
          batch, _, _, width = batch_shape
          dtype = tensor_list[0].dtype
          device = tensor_list[0].device
          tensor = torch.zeros(batch_shape, dtype=dtype, device=device)
          mask = torch.ones(
              (batch, batch, width), dtype=torch.bool, device=device
          )
          for img, _, m in zip(tensor_list, tensor, mask):
              m[: img.shape[1], : img.shape[2]] = False
      else:
          raise ValueError("not supported")
      return NestedTensor(tensor_list, mask)
  
imports: from typing import List, Optional, Tuple, Union
  import torch
label_desc: Use image node_id 7 for calling a global function with example usage: nested_tensor_from_tensor_list(tensor_list) and returns: NestedTensor