class_docstr: This class generators samples from a user provided frequency map for each
  input volume. The sampling likelihood of each voxel is proportional its
  intra class frequency. That is, if a given voxel is of class `A` and there
  are 20 voxels with class `A`, the probability of selecting this voxel is
  5%. If there are 10 classes, the probability becomes 10% * 5% = 0.5%.
  
  In general, the likelihood of sampling a voxel is given by:
      p(v) = (1)/(# of unique labels * # of voxels with same class as v)
  
  This is done for balanced sampling. In the case of unbalanced labels,
  this sampler should produce a roughly equal probability of sampling each
  class.
  
  This layer can be considered as a "balanced random cropping" layer of the
  input image.
class_docstr_tok: ["This","class","generators","samples","from","a","user","provided","frequency","map","for","each","input","volume",".","The","sampling","likelihood","of","each","voxel","is","proportional","its","intra","class","frequency",".","That","is",",","if","a","given","voxel","is","of","class","`","A","`","and","there","are","20","voxels","with","class","`","A","`",",","the","probability","of","selecting","this","voxel","is","5","%",".","If","there","are","10","classes",",","the","probability","becomes","10","%","*","5","%","=","0.5","%",".","In","general",",","the","likelihood","of","sampling","a","voxel","is","given","by",":","p","(","v",")","=","(","1",")","\/","(","#","of","unique","labels","*","#","of","voxels","with","same","class","as","v",")","This","is","done","for","balanced","sampling",".","In","the","case","of","unbalanced","labels",",","this","sampler","should","produce","a","roughly","equal","probability","of","sampling","each","class",".","This","layer","can","be","considered","as","a","``","balanced","random","cropping","''","layer","of","the","input","image","."]
code: def __init__(
      self,
      reader,
      csv_reader,
      window_sizes,
      batch_size=1,
      windows_per_image=1,
      queue_length=10,
      name="balanced_sampler",
  ):
      UniformSamplerCSV.__init__(
          self,
          reader=reader,
          csv_reader=csv_reader,
          window_sizes=window_sizes,
          batch_size=batch_size,
          windows_per_image=windows_per_image,
          queue_length=queue_length,
          name=name,
      )
      tf.logging.info("Initialised balanced sampler window instance")
      self.window_centers_sampler = balanced_spatial_coordinates
  
file_path: NiftyNet/niftynet/contrib/csv_reader/sampler_balanced_v2_csv.py
imports: from __future__ import absolute_import, division, print_function
  import numpy
  import tensorflow
  from niftynet.engine.sampler_uniform_v2 import UniformSampler
  from niftynet.contrib.csv_reader.sampler_uniform_v2_csv import UniformSamplerCSV
  from niftynet.engine.image_window import N_SPATIAL
  from niftynet.engine.sampler_weighted_v2 import crop_sampling_map
label_desc: Use image node_id 1 to create a new BalancedSamplerCSV object from inherited base classes: UniformSampler with example: obj = BalancedSamplerCSV(reader, csv_reader, window_sizes, batch_size, windows_per_image, queue_length, name)