def nested_tensor_from_tensor_list(tensor_list: 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)

    Adapted from DETR source: https://github.com/facebookresearch/detr
    (detr/util/misc.py)
    
art/estimators/object_detection/detr.py