# Path: moonlight/models/base/glyph_patches.py
# WEIGHT_COLUMN_NAME = 'weight'
# FLAGS = flags.FLAGS
# def read_patch_dimensions():
# def input_fn(input_patches):
#   def parser(record):
# def _augment(patch):
# def _augment_shift(patch):
#     def shift_left():
#     def shift_right():
#     def identity():
# def _shift_left(patch):
# def _shift_right(patch):
# def _augment_rotation(patch):
# def serving_fn():
# def create_patch_feature_column():
# def multiclass_binary_metric(class_number, binary_metric, labels, predictions):
# def metrics_fn(features, labels, predictions):
# def train_and_evaluate(estimator):
# 
# Path: moonlight/models/base/hyperparameters.py
# def estimator_with_saved_params(estimator, params):
#   def model_fn(features, labels, mode, params, config):


from absl import flags
from moonlight.models.base import glyph_patches
from moonlight.models.base import hyperparameters
from moonlight.protobuf import musicscore_pb2
import tensorflow as tf


def create_estimator(params=None):
  """Returns the glyphs DNNClassifier estimator.

  Args:
    params: Optional hyperparameters, defaulting to command-line values.

  Returns:
    A DNNClassifier instance.
  """
  params = params or get_flag_params()
  if not params['layer_dims'] and params['activation_fn'] != 'sigmoid':
    tf.logging.warning(
        'activation_fn should be sigmoid for logistic regression. Got: %s',
        params['activation_fn'])

  activation_fn = getattr(tf.nn, params['activation_fn'])
  estimator = tf.estimator.DNNClassifier(
      params['layer_dims'],
      feature_columns=[glyph_patches.create_patch_feature_column()],
      weight_column=glyph_patches.WEIGHT_COLUMN_NAME,
      n_classes=len(musicscore_pb2.Glyph.Type.keys()),
      optimizer=tf.train.FtrlOptimizer(
          learning_rate=params['learning_rate'],
          l1_regularization_strength=params['l1_regularization_strength'],
          l2_regularization_strength=params['l2_regularization_strength'],
      ),
      activation_fn=activation_fn,
      dropout=FLAGS.dropout,

# Path: moonlight/models/base/glyph_patches.py
# WEIGHT_COLUMN_NAME = 'weight'
# FLAGS = flags.FLAGS
# def read_patch_dimensions():
# def input_fn(input_patches):
#   def parser(record):
# def _augment(patch):
# def _augment_shift(patch):
#     def shift_left():
#     def shift_right():
#     def identity():
# def _shift_left(patch):
# def _shift_right(patch):
# def _augment_rotation(patch):
# def serving_fn():
# def create_patch_feature_column():
# def multiclass_binary_metric(class_number, binary_metric, labels, predictions):
# def metrics_fn(features, labels, predictions):
# def train_and_evaluate(estimator):
# 
# Path: moonlight/models/base/hyperparameters.py
# def estimator_with_saved_params(estimator, params):
#   def model_fn(features, labels, mode, params, config):


# Path: moonlight/models/glyphs_dnn/model.py
from absl import flags
from moonlight.models.base import glyph_patches
from moonlight.models.base import hyperparameters
from moonlight.protobuf import musicscore_pb2
import tensorflow as tf



def create_estimator(params=None):
  """Returns the glyphs DNNClassifier estimator.

  Args:
    params: Optional hyperparameters, defaulting to command-line values.

  Returns:
    A DNNClassifier instance.
  """
  params = params or get_flag_params()
  if not params['layer_dims'] and params['activation_fn'] != 'sigmoid':
    tf.logging.warning(
        'activation_fn should be sigmoid for logistic regression. Got: %s',
        params['activation_fn'])

  activation_fn = getattr(tf.nn, params['activation_fn'])
  estimator = tf.estimator.DNNClassifier(
      params['layer_dims'],
      feature_columns=[glyph_patches.create_patch_feature_column()],
      weight_column=glyph_patches.WEIGHT_COLUMN_NAME,
      n_classes=len(musicscore_pb2.Glyph.Type.keys()),
      optimizer=tf.train.FtrlOptimizer(
          learning_rate=params['learning_rate'],
          l1_regularization_strength=params['l1_regularization_strength'],
          l2_regularization_strength=params['l2_regularization_strength'],
      ),
      activation_fn=activation_fn,
      dropout=FLAGS.dropout,

      model_dir=glyph_patches.FLAGS.model_dir,