class_docstr: Batch data that have similar aspect ratio together.
  In this implementation, images whose aspect ratio < (or >) 1 will
  be batched together.
  This improves training speed because the images then need less padding
  to form a batch.
  
  It assumes the underlying dataset produces dicts with "width" and "height" keys.
  It will then produce a list of original dicts with length = batch_size,
  all with similar aspect ratios.
class_docstr_tok: ["Batch","data","that","have","similar","aspect","ratio","together",".","In","this","implementation",",","images","whose","aspect","ratio","<","(","or",">",")","1","will","be","batched","together",".","This","improves","training","speed","because","the","images","then","need","less","padding","to","form","a","batch",".","It","assumes","the","underlying","dataset","produces","dicts","with","``","width","''","and","``","height","''","keys",".","It","will","then","produce","a","list","of","original","dicts","with","length","=","batch_size",",","all","with","similar","aspect","ratios","."]
docstr: Args:
      dataset: an iterable. Each element must be a dict with keys
          "width" and "height", which will be used to batch data.
      batch_size (int):
docstr_tok: ["Args",":","dataset",":","an","iterable",".","Each","element","must","be","a","dict","with","keys","``","width","''","and","``","height","''",",","which","will","be","used","to","batch","data",".","batch_size","(","int",")",":"]
code: def __init__(self, dataset, batch_size):
      """
      Args:
          dataset: an iterable. Each element must be a dict with keys
              "width" and "height", which will be used to batch data.
          batch_size (int):
      """
      self.dataset = dataset
      self.batch_size = batch_size
      self._buckets = [[] for _ in range(2)]
  
imports: import contextlib
  import copy
  import itertools
  import logging
  import numpy
  import pickle
  import random
  from typing import Callable, Union
  import torch
  import torch.utils.data
  from torch.utils.data.sampler import Sampler
  from detectron2.utils.serialize import PicklableWrapper
label_desc: Use image node_id 1 to create a new AspectRatioGroupedDataset object from inherited base classes: data with example: obj = AspectRatioGroupedDataset(dataset, batch_size)