    def _pack_image_list(
        self,
        images: List[FloatTensor],
        sizes: List[IntTensor],
    ) -> ImagesWithSize:
        """
        A helper method that subclasses can use to turn a list of individual images into a padded
        batch.
        """
        # Adapted from
        # https://github.com/facebookresearch/detectron2/blob/master/detectron2/structures/image_list.py.

        # shape: (batch_size, 2)
        size_tensor = torch.stack(sizes)  # type: ignore[arg-type]

        # shape: (2,)
        max_size = size_tensor.max(0).values

        if self.size_divisibility > 1:
            # shape: (2,)
            max_size = (
                (max_size + self.size_divisibility - 1) // self.size_divisibility
            ) * self.size_divisibility

        batched_shape = [len(images)] + list(images[0].shape[:-2]) + list(max_size)

        # shape: (batch_size, color_channels, max_height, max_width)
        batched_images = images[0].new_full(batched_shape, self.pad_value)

        for image, batch_slice, size in zip(images, batched_images, size_tensor):
            batch_slice[..., : image.shape[-2], : image.shape[-1]].copy_(image)

        return cast(FloatTensor, batched_images), cast(IntTensor, size_tensor)
A helper method that subclasses can use to turn a list of individual images into a padded
batch.
allennlp/data/image_loader.py