class_docstr: This class is used to build 2D segmentation datasets. It represents
  a pair of of two data volumes (the input data and the ground truth data).
  
  :param input_filename: the input filename (supported by nibabel).
  :param gt_filename: the ground-truth filename.
  :param cache: if the data should be cached in memory or not.
  :param canonical: canonical reordering of the volume axes.
class_docstr_tok: ["This","class","is","used","to","build","2D","segmentation","datasets",".","It","represents","a","pair","of","of","two","data","volumes","(","the","input","data","and","the","ground","truth","data",")",".",":","param","input_filename",":","the","input","filename","(","supported","by","nibabel",")",".",":","param","gt_filename",":","the","ground-truth","filename",".",":","param","cache",":","if","the","data","should","be","cached","in","memory","or","not",".",":","param","canonical",":","canonical","reordering","of","the","volume","axes","."]
code: def __init__(
      self, input_filename, gt_filename, cache=True, canonical=False
  ):
      self.input_filename = input_filename
      self.gt_filename = gt_filename
      self.canonical = canonical
      self.cache = cache
  
      self.input_handle = nib.load(self.input_filename)
  
      # Unlabeled data (inference time)
      if self.gt_filename is None:
          self.gt_handle = None
      else:
          self.gt_handle = nib.load(self.gt_filename)
  
      if len(self.input_handle.shape) > 3:
          raise RuntimeError("4-dimensional volumes not supported.")
  
      # Sanity check for dimensions, should be the same
      input_shape, gt_shape = self.get_pair_shapes()
  
      if self.gt_handle is not None:
          if not np.allclose(input_shape, gt_shape):
              raise RuntimeError(
                  "Input and ground truth with different dimensions."
              )
  
      if self.canonical:
          self.input_handle = nib.as_closest_canonical(
              self.input_handle
          )
  
          # Unlabeled data
          if self.gt_handle is not None:
              self.gt_handle = nib.as_closest_canonical(self.gt_handle)
  
imports: import os
  import re
  import collections
  from medicaltorch import transforms
  from tqdm import tqdm
  import numpy
  import nibabel
  from torch.utils.data import Dataset
  import torch
  from torch._six import string_classes, int_classes
  from PIL import Image
label_desc: Use image node_id 1 to create a new SegmentationPair2D object from inherited base classes: object with example: obj = SegmentationPair2D(input_filename, gt_filename, cache, canonical)