class_docstr: This is a generic class for 2D (slice-wise) segmentation datasets.
  
  :param filename_pairs: a list of tuples in the format (input filename,
                         ground truth filename).
  :param slice_axis: axis to make the slicing (default axial).
  :param cache: if the data should be cached in memory or not.
  :param transform: transformations to apply.
class_docstr_tok: ["This","is","a","generic","class","for","2D","(","slice-wise",")","segmentation","datasets",".",":","param","filename_pairs",":","a","list","of","tuples","in","the","format","(","input","filename",",","ground","truth","filename",")",".",":","param","slice_axis",":","axis","to","make","the","slicing","(","default","axial",")",".",":","param","cache",":","if","the","data","should","be","cached","in","memory","or","not",".",":","param","transform",":","transformations","to","apply","."]
code: def __init__(
      self,
      filename_pairs,
      slice_axis=2,
      cache=True,
      transform=None,
      slice_filter_fn=None,
      canonical=False,
  ):
      self.filename_pairs = filename_pairs
      self.handlers = []
      self.indexes = []
      self.transform = transform
      self.cache = cache
      self.slice_axis = slice_axis
      self.slice_filter_fn = slice_filter_fn
      self.canonical = canonical
  
      self._load_filenames()
      self._prepare_indexes()
  
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 MRI2DSegmentationDataset object from inherited base classes: Dataset with example: obj = MRI2DSegmentationDataset(filename_pairs, slice_axis, cache, transform, slice_filter_fn, canonical)