class_docstr: An `ImageLoader` is a callable that takes as input one or more filenames, and outputs two
  tensors: one representing the images themselves, and one that just holds the sizes
  of each image.
  
  The first tensor is the images and is of shape `(batch_size, color_channels, height, width)`.
  The second tensor is the sizes and is of shape `(batch_size, 2)`, where
  the last dimension contains the height and width, respectively.
  
  If only a single image is passed (as a `Path` or `str`, instead of a list) then
  the batch dimension will be removed.
  
  Subclasses only need to implement the `load()` method, which should load a single image
  from a path.
  
  # Parameters
  
  size_divisibility : `int`, optional (default = `0`)
      If set to a positive number, padding will be added so that the height
      and width dimensions are divisible by `size_divisibility`.
      Certain models may require this.
  
  pad_value : `float`, optional (default = `0.0`)
      The value to use for padding.
  
  device : `Union[str, torch.device]`, optional (default = `"cpu"`)
      A torch device identifier to put the image and size tensors on.
class_docstr_tok: ["An","`","ImageLoader","`","is","a","callable","that","takes","as","input","one","or","more","filenames",",","and","outputs","two","tensors",":","one","representing","the","images","themselves",",","and","one","that","just","holds","the","sizes","of","each","image",".","The","first","tensor","is","the","images","and","is","of","shape","`","(","batch_size",",","color_channels",",","height",",","width",")","`",".","The","second","tensor","is","the","sizes","and","is","of","shape","`","(","batch_size",",","2",")","`",",","where","the","last","dimension","contains","the","height","and","width",",","respectively",".","If","only","a","single","image","is","passed","(","as","a","`","Path","`","or","`","str","`",",","instead","of","a","list",")","then","the","batch","dimension","will","be","removed",".","Subclasses","only","need","to","implement","the","`","load","(",")","`","method",",","which","should","load","a","single","image","from","a","path",".","#","Parameters","size_divisibility",":","`","int","`",",","optional","(","default","=","`","0","`",")","If","set","to","a","positive","number",",","padding","will","be","added","so","that","the","height","and","width","dimensions","are","divisible","by","`","size_divisibility","`",".","Certain","models","may","require","this",".","pad_value",":","`","float","`",",","optional","(","default","=","`","0.0","`",")","The","value","to","use","for","padding",".","device",":","`","Union","[","str",",","torch.device","]","`",",","optional","(","default","=","`","``","cpu","''","`",")","A","torch","device","identifier","to","put","the","image","and","size","tensors","on","."]
docstr: A helper method that subclasses can use to turn a list of individual images into a padded
  batch.
docstr_tok: ["A","helper","method","that","subclasses","can","use","to","turn","a","list","of","individual","images","into","a","padded","batch","."]
code: 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
      )
  
file_path: allennlp/allennlp/data/image_loader.py
imports: from os import PathLike
  from typing import Union, Sequence, Tuple, List, cast
  import torch
  import torchvision
  from torch import FloatTensor, IntTensor
  from allennlp.common.file_utils import cached_path
  from allennlp.common.registrable import Registrable
label_desc: Use image node_id 4 for calling the ImageLoader obj's underlying member method code with example usage: obj._pack_image_list(images, sizes) and returns: cast,  cast