class_docstr: A data class to hold images of different sizes in a batch.
  
  It contains `tensors` to hold padded images to the maximum size and `mask` to
  indicate the actual image region of each padded image
docstr: convert a list of images in CHW format in `tensor_list` to a NestedTensor by
  padding them to maximum image size.
docstr_tok: ["convert","a","list","of","images","in","CHW","format","in","`","tensor_list","`","to","a","NestedTensor","by","padding","them","to","maximum","image","size","."]
code: def from_tensor_list(cls, tensor_list: List[Tensor]):
      """
      convert a list of images in CHW format in `tensor_list` to a NestedTensor by
      padding them to maximum image size.
      """
      if tensor_list[0].ndim == 3:
          max_size = tuple(
              max(s) for s in zip(*[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, c, 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 Exception(
              "tensor_list must contain images in CHW format"
          )
      return cls(tensor, mask)
  
imports: from typing import List
  import torch
  from torch import Tensor
label_desc: Use image node_id 4 for calling the NestedTensor obj's underlying member method code with example usage: obj.from_tensor_list(cls, tensor_list) and returns: cls