class_docstr: Base class for other collate implementations.
  
  Takes a batch of images as input and transforms each image into two
  different augmentations with the help of random transforms. The images are
  then concatenated such that the output batch is exactly twice the length
  of the input batch.
  
  Attributes:
      transform:
          A set of torchvision transforms which are randomly applied to
          each image.
class_docstr_tok: ["Base","class","for","other","collate","implementations",".","Takes","a","batch","of","images","as","input","and","transforms","each","image","into","two","different","augmentations","with","the","help","of","random","transforms",".","The","images","are","then","concatenated","such","that","the","output","batch","is","exactly","twice","the","length","of","the","input","batch",".","Attributes",":","transform",":","A","set","of","torchvision","transforms","which","are","randomly","applied","to","each","image","."]
docstr: Turns a batch of tuples into a tuple of batches.
  
  Args:
      batch:
          A batch of tuples of images, labels, and filenames which
          is automatically provided if the dataloader is built from
          a LightlyDataset.
  
  Returns:
      A tuple of images, labels, and filenames. The images consist of
      two batches corresponding to the two transformations of the
      input images.
  
  Examples:
      >>> # define a random transformation and the collate function
      >>> transform = ... # some random augmentations
      >>> collate_fn = BaseCollateFunction(transform)
      >>>
      >>> # input is a batch of tuples (here, batch_size = 1)
      >>> input = [(img, 0, 'my-image.png')]
      >>> output = collate_fn(input)
      >>>
      >>> # output consists of two random transforms of the images,
      >>> # the labels, and the filenames in the batch
      >>> (img_t0, img_t1), label, filename = output
docstr_tok: ["Turns","a","batch","of","tuples","into","a","tuple","of","batches",".","Args",":","batch",":","A","batch","of","tuples","of","images",",","labels",",","and","filenames","which","is","automatically","provided","if","the","dataloader","is","built","from","a","LightlyDataset",".","Returns",":","A","tuple","of","images",",","labels",",","and","filenames",".","The","images","consist","of","two","batches","corresponding","to","the","two","transformations","of","the","input","images",".","Examples",":",">",">",">","#","define","a","random","transformation","and","the","collate","function",">",">",">","transform","=","...","#","some","random","augmentations",">",">",">","collate_fn","=","BaseCollateFunction","(","transform",")",">",">",">",">",">",">","#","input","is","a","batch","of","tuples","(","here",",","batch_size","=","1",")",">",">",">","input","=","[","(","img",",","0",",","'my-image.png","'",")","]",">",">",">","output","=","collate_fn","(","input",")",">",">",">",">",">",">","#","output","consists","of","two","random","transforms","of","the","images",",",">",">",">","#","the","labels",",","and","the","filenames","in","the","batch",">",">",">","(","img_t0",",","img_t1",")",",","label",",","filename","=","output"]
code: def forward(self, batch: List[Tuple[Image.Image, int, str]]):
      """Turns a batch of tuples into a tuple of batches.
  
      Args:
          batch:
              A batch of tuples of images, labels, and filenames which
              is automatically provided if the dataloader is built from
              a LightlyDataset.
  
      Returns:
          A tuple of images, labels, and filenames. The images consist of
          two batches corresponding to the two transformations of the
          input images.
  
      Examples:
          >>> # define a random transformation and the collate function
          >>> transform = ... # some random augmentations
          >>> collate_fn = BaseCollateFunction(transform)
          >>>
          >>> # input is a batch of tuples (here, batch_size = 1)
          >>> input = [(img, 0, 'my-image.png')]
          >>> output = collate_fn(input)
          >>>
          >>> # output consists of two random transforms of the images,
          >>> # the labels, and the filenames in the batch
          >>> (img_t0, img_t1), label, filename = output
  
      """
      batch_size = len(batch)
  
      # list of transformed images
      transforms = [
          self.transform(batch[i % batch_size][0]).unsqueeze_(0)
          for i in range(2 * batch_size)
      ]
      # list of labels
      labels = torch.LongTensor([item[1] for item in batch])
      # list of filenames
      fnames = [item[2] for item in batch]
  
      # tuple of transforms
      transforms = (
          torch.cat(transforms[:batch_size], 0),
          torch.cat(transforms[batch_size:], 0),
      )
  
      return transforms, labels, fnames
  
imports: import math
  from multiprocessing import Value
  from typing import List, Optional, Tuple, Union
  from warnings import warn
  import torch
  import torch.nn
  import torchvision
  import torchvision.transforms
  from PIL import Image
  from lightly.transforms import GaussianBlur, Jigsaw, RandomSolarization
  from lightly.transforms.random_crop_and_flip_with_grid import RandomResizedCropAndFlip
  from lightly.transforms.rotation import random_rotation_transform
  from lightly.transforms.utils import IMAGENET_NORMALIZE
label_desc: Use image node_id 2 for calling the BaseCollateFunction obj's underlying member method code with example usage: obj.forward(batch) and returns: transforms,  labels,  fnames