code: def nested_tensor_from_tensor_list(tensor_list: List[Tensor]):
      # TODO make this more general
      if tensor_list[0].ndim == 3:
          # TODO make it support different-sized images
          max_size = _max_by_axis(
              [list(img.shape) for img in tensor_list]
          )
          # min_size = tuple(min(s) for s in zip(*[img.shape for img in tensor_list]))
          batch_shape = [len(tensor_list)] + max_size
          b, _, h, w = batch_shape
          dtype = tensor_list[0].dtype
          device = tensor_list[0].device
          tensor = torch.zeros(batch_shape, dtype=dtype, device=device)
          mask = torch.ones((b, h, w), dtype=torch.bool, device=device)
          for img, pad_img, m in zip(tensor_list, tensor, mask):
              pad_img[
                  : img.shape[0], : img.shape[1], : img.shape[2]
              ].copy_(img)
              m[: img.shape[1], : img.shape[2]] = False
      else:
          raise ValueError("not supported")
      return NestedTensor(tensor, mask)
  
file_path: towhee/towhee/models/coformer/utils.py
imports: import torch
  from torch import Tensor
  import torch.distributed
  from typing import Optional, List
label_desc: Use image node_id 5 for calling a global function with example usage: nested_tensor_from_tensor_list(tensor_list) and returns: NestedTensor