def __init__()

in moonlight/staves/staffline_extractor.py [0:0]


  def __init__(self,
               num_sections=DEFAULT_NUM_SECTIONS,
               patch_height=15,
               patch_width=12,
               run_options=None):
    self.num_sections = num_sections
    self.patch_height = patch_height
    self.patch_width = patch_width
    self.run_options = run_options

    self.graph = tf.Graph()
    with self.graph.as_default():
      # Identifying information for the patch.
      self.filename = tf.placeholder(tf.string, name='filename')
      self.staff_index = tf.placeholder(tf.int64, name='staff_index')
      self.y_position = tf.placeholder(tf.int64, name='y_position')

      image = image_module.decode_music_score_png(tf.read_file(self.filename))
      staff_detector = staves_module.StaffDetector(image)
      staff_remover = removal.StaffRemover(staff_detector)
      extractor = StafflineExtractor(
          staff_remover.remove_staves,
          staff_detector,
          num_sections=num_sections,
          target_height=patch_height)
      # Index into the staff strips array, where a y position of 0 is the center
      # element. Positive positions count up (towards higher notes, towards the
      # top of the image, and smaller indices into the array).
      position_index = num_sections // 2 - self.y_position
      self.all_stafflines = extractor.extract_staves()
      # The entire extracted horizontal strip of the image.
      self.staffline = self.all_stafflines[self.staff_index, position_index]

      # Determine the scale for converting image x coordinates to the scaled
      # staff strip from which the patch is extracted.
      extracted_staff_strip_height = tf.shape(self.all_stafflines)[2]
      unscaled_staff_strip_heights = tf.multiply(
          DEFAULT_STAFFLINE_DISTANCE_MULTIPLE,
          staff_detector.staffline_distance)
      self.all_staffline_scales = tf.divide(
          tf.to_float(extracted_staff_strip_height),
          tf.to_float(unscaled_staff_strip_heights))
      self.staffline_scale = self.all_staffline_scales[self.staff_index]