class_docstr: This is the Spinal Cord Gray Matter Challenge dataset.
  
  :param root_dir: the directory containing the training dataset.
  :param site_ids: a list of site ids to filter (i.e. [1, 3]).
  :param subj_ids: the list of subject ids to filter.
  :param rater_ids: the list of the rater ids to filter.
  :param transform: the transformations that should be applied.
  :param cache: if the data should be cached in memory or not.
  :param slice_axis: axis to make the slicing (default axial).
  
  .. note:: This dataset assumes that you only have one class in your
            ground truth mask (w/ 0's and 1's). It also doesn't
            automatically resample the dataset.
  
  .. seealso::
      Prados, F., et al (2017). Spinal cord grey matter
      segmentation challenge. NeuroImage, 152, 312–329.
      https://doi.org/10.1016/j.neuroimage.2017.03.010
  
      Challenge Website:
      http://cmictig.cs.ucl.ac.uk/spinal-cord-grey-matter-segmentation-challenge
class_docstr_tok: ["This","is","the","Spinal","Cord","Gray","Matter","Challenge","dataset",".",":","param","root_dir",":","the","directory","containing","the","training","dataset",".",":","param","site_ids",":","a","list","of","site","ids","to","filter","(","i.e",".","[","1",",","3","]",")",".",":","param","subj_ids",":","the","list","of","subject","ids","to","filter",".",":","param","rater_ids",":","the","list","of","the","rater","ids","to","filter",".",":","param","transform",":","the","transformations","that","should","be","applied",".",":","param","cache",":","if","the","data","should","be","cached","in","memory","or","not",".",":","param","slice_axis",":","axis","to","make","the","slicing","(","default","axial",")",".","..","note",":",":","This","dataset","assumes","that","you","only","have","one","class","in","your","ground","truth","mask","(","w\/","0","'s","and","1","'s",")",".","It","also","doesn't","automatically","resample","the","dataset",".","..","seealso",":",":","Prados",",","F.",",","et","al","(","2017",")",".","Spinal","cord","grey","matter","segmentation","challenge",".","NeuroImage",",","152",",","312\u2013329",".","https",":","\/\/doi.org\/10.1016\/j.neuroimage.2017.03.010","Challenge","Website",":","http",":","\/\/cmictig.cs.ucl.ac.uk\/spinal-cord-grey-matter-segmentation-challenge"]
code: def __init__(
      self,
      root_dir,
      slice_axis=2,
      site_ids=None,
      subj_ids=None,
      rater_ids=None,
      cache=True,
      transform=None,
      slice_filter_fn=None,
      canonical=False,
      labeled=True,
  ):
      self.labeled = labeled
      self.root_dir = root_dir
      self.site_ids = site_ids or range(
          1, SCGMChallenge2DTrain.NUM_SITES + 1
      )
      self.subj_ids = subj_ids or range(
          1, SCGMChallenge2DTrain.NUM_SUBJECTS + 1
      )
      self.rater_ids = rater_ids or range(
          1, SCGMChallenge2DTrain.NUM_RATERS + 1
      )
  
      self.filename_pairs = []
  
      for site_id in self.site_ids:
          for subj_id in self.subj_ids:
              if len(self.rater_ids) > 0:
                  for rater_id in self.rater_ids:
                      input_filename = self._build_train_input_filename(
                          site_id, subj_id
                      )
                      gt_filename = self._build_train_input_filename(
                          site_id, subj_id, rater_id
                      )
  
                      input_filename = os.path.join(
                          self.root_dir, input_filename
                      )
                      gt_filename = os.path.join(
                          self.root_dir, gt_filename
                      )
  
                      if not self.labeled:
                          gt_filename = None
  
                      self.filename_pairs.append(
                          (input_filename, gt_filename)
                      )
              else:
                  input_filename = self._build_train_input_filename(
                      site_id, subj_id
                  )
                  gt_filename = None
                  input_filename = os.path.join(
                      self.root_dir, input_filename
                  )
  
                  if not self.labeled:
                      gt_filename = None
  
                  self.filename_pairs.append(
                      (input_filename, gt_filename)
                  )
  
      super().__init__(
          self.filename_pairs,
          slice_axis,
          cache,
          transform,
          slice_filter_fn,
          canonical,
      )
  
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 SCGMChallenge2DTrain object from inherited base classes: MRI2DSegmentationDataset with example: obj = SCGMChallenge2DTrain(root_dir, slice_axis, site_ids, subj_ids, rater_ids, cache, transform, slice_filter_fn, canonical, labeled)