# Path: moonlight/glyphs/convolutional.py
# DEFAULT_RUN_MIN_LENGTH = 3
# class Convolutional1DGlyphClassifier(base.BaseGlyphClassifier):
#   def __init__(self, run_min_length=DEFAULT_RUN_MIN_LENGTH):
#   def staffline_predictions(self):
#   def _build_detected_glyphs(self, predictions_arr):
#   def _create_glyph_arr(self, staff_index, y_position, x, type_value):
#   def get_detected_glyphs(self):
# 
# Path: moonlight/glyphs/corpus.py
# def get_patch_shape(corpus_file):
# def parse_corpus(corpus_file, height, width):
# 
# Path: moonlight/util/patches.py
# def patches_1d(images, patch_width):
#   def do_extract_patches():
#   def empty_patches():


import tensorflow as tf
from moonlight.glyphs import convolutional
from moonlight.glyphs import corpus
from moonlight.protobuf import musicscore_pb2
from moonlight.util import patches
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



# k = 3 has the best performance for noteheads, clefs, and sharps. k = 5 seems
# to increase false negatives, so we probably don't want to increase k further
# with our current data.
K_NEAREST_VALUE = 3

NUM_GLYPHS = len(musicscore_pb2.Glyph.Type.keys())


class NearestNeighborGlyphClassifier(
    convolutional.Convolutional1DGlyphClassifier):
  """Classifies staffline patches using 1 nearest neighbor."""

  def __init__(self, corpus_file, staffline_extractor, **kwargs):
    """Build a 1-nearest-neighbor classifier with labeled patches.

    Args:
      corpus_file: Path to the TFRecords of Examples with patch (cluster) values
        in the "patch" feature, and the glyph label in the "label" feature.
      staffline_extractor: The staffline extractor.
      **kwargs: Passed through to `Convolutional1DGlyphClassifier`.
    """
    super(NearestNeighborGlyphClassifier, self).__init__(**kwargs)

    patch_height, patch_width = corpus.get_patch_shape(corpus_file)

# Path: moonlight/glyphs/convolutional.py
# DEFAULT_RUN_MIN_LENGTH = 3
# class Convolutional1DGlyphClassifier(base.BaseGlyphClassifier):
#   def __init__(self, run_min_length=DEFAULT_RUN_MIN_LENGTH):
#   def staffline_predictions(self):
#   def _build_detected_glyphs(self, predictions_arr):
#   def _create_glyph_arr(self, staff_index, y_position, x, type_value):
#   def get_detected_glyphs(self):
# 
# Path: moonlight/glyphs/corpus.py
# def get_patch_shape(corpus_file):
# def parse_corpus(corpus_file, height, width):
# 
# Path: moonlight/util/patches.py
# def patches_1d(images, patch_width):
#   def do_extract_patches():
#   def empty_patches():


# Path: moonlight/glyphs/knn.py
import tensorflow as tf
from moonlight.glyphs import convolutional
from moonlight.glyphs import corpus
from moonlight.protobuf import musicscore_pb2
from moonlight.util import patches

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



# k = 3 has the best performance for noteheads, clefs, and sharps. k = 5 seems
# to increase false negatives, so we probably don't want to increase k further
# with our current data.
K_NEAREST_VALUE = 3

NUM_GLYPHS = len(musicscore_pb2.Glyph.Type.keys())


class NearestNeighborGlyphClassifier(
    convolutional.Convolutional1DGlyphClassifier):
  """Classifies staffline patches using 1 nearest neighbor."""

  def __init__(self, corpus_file, staffline_extractor, **kwargs):
    """Build a 1-nearest-neighbor classifier with labeled patches.

    Args:
      corpus_file: Path to the TFRecords of Examples with patch (cluster) values
        in the "patch" feature, and the glyph label in the "label" feature.
      staffline_extractor: The staffline extractor.
      **kwargs: Passed through to `Convolutional1DGlyphClassifier`.
    """
    super(NearestNeighborGlyphClassifier, self).__init__(**kwargs)

    patch_height, patch_width = corpus.get_patch_shape(corpus_file)

    centroids, labels = corpus.parse_corpus(corpus_file, patch_height,