# Path: settings.py
# FLAGS = flags.FLAGS
# OUT_DIR = '/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21'
# DUMP_DIR = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21"
# TF_RECORDS_DIR = "/localhome/rothfuss/data/20bn-something/tf_records_train"
# MODE = 'valid_mode'
# VALID_MODE = 'data_frame' #'data_frame gif'
# NUM_IMAGES = 15
# NUM_DEPTH = 3
# WIDTH = 128
# HEIGHT = 128
# NUM_THREADS_QUEUERUNNER = 32 # specifies the number of pre-processing threads
# PRETRAINED_MODEL = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21"
# EXCLUDE_FROM_RESTORING = None
# FINE_TUNING_WEIGHTS_LIST = None
# INPUT_DIR = ""
# MEMORY_PATH = ""
# LOSS_FUNCTIONS = ['mse', 'gdl', 'mse_gdl', 'vae']
# MODES = ["train_mode", "valid_mode", "feeding_mode"]
# VALID_MODES = ['count_trainable_weights', 'vector', 'gif', 'similarity', 'data_frame', 'psnr', 'memory_prep', 'measure_test_time']
# 
# Path: models/loss_functions.py
# def gradient_difference_loss(true, pred, alpha=2.0):
# def difference_gradient(image, vertical=True):
# def mean_squared_error(true, pred):
# def peak_signal_to_noise_ratio(true, pred):
# def kl_penalty(mu, sigma):
# def decoder_loss(frames_gen, frames_original, loss_fun):
# def decoder_psnr(frames_gen, frames_original):
# def composite_loss(original_frames, frames_pred, frames_reconst, loss_fun='mse',
#                    encoder_length=5, decoder_future_length=5,
#                    decoder_reconst_length=5, mu_latent=None, sigm_latent=None):


import tensorflow as tf
import math
import numpy as np
import data_prep.model_input as input
from pprint import pprint
from settings import FLAGS, model
from models import loss_functions
          self.loss = average_losses(tower_losses)
          # concatenate outputs of towers to one large tensor each
          self.frames_pred = tf.unstack(tf.concat(1, frames_pred_list))
          self.frames_reconst = tf.unstack(tf.concat(1, frames_reconst_list))
          self.hidden_repr = tf.concat(0, hidden_repr_list)
          self.label = tf.concat(0, label_batch_list)
          self.metadata = tf.concat(0, metadata_batch_list)
          val_set = tf.concat(0, val_batch_list)

      self.add_image_summary(summary_prefix, val_set, FLAGS.encoder_length, FLAGS.decoder_future_length,
                             FLAGS.decoder_reconst_length)

      # evaluate frame predictions for storing on disk
      self.output_frames = self.frames_reconst + self.frames_pred  # join arrays of tensors


      self.summaries.append(tf.summary.scalar(summary_prefix + '_loss', self.loss))
      self.sum_op = tf.summary.merge(self.summaries)


class FeedingValidationModel(Model):
  def __init__(self, scope_name='feeding_model', reuse_scope=None):
    print("Constructing FeedingModel")
    with tf.variable_scope(scope_name, reuse=None):
      Model.__init__(self)

      assert reuse_scope is not None

      with tf.variable_scope(reuse_scope, reuse=True):
        "5D array of batch with videos - shape(batch_size, num_frames, frame_width, frame_higth, num_channels)"

# Path: settings.py
# FLAGS = flags.FLAGS
# OUT_DIR = '/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21'
# DUMP_DIR = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21"
# TF_RECORDS_DIR = "/localhome/rothfuss/data/20bn-something/tf_records_train"
# MODE = 'valid_mode'
# VALID_MODE = 'data_frame' #'data_frame gif'
# NUM_IMAGES = 15
# NUM_DEPTH = 3
# WIDTH = 128
# HEIGHT = 128
# NUM_THREADS_QUEUERUNNER = 32 # specifies the number of pre-processing threads
# PRETRAINED_MODEL = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21"
# EXCLUDE_FROM_RESTORING = None
# FINE_TUNING_WEIGHTS_LIST = None
# INPUT_DIR = ""
# MEMORY_PATH = ""
# LOSS_FUNCTIONS = ['mse', 'gdl', 'mse_gdl', 'vae']
# MODES = ["train_mode", "valid_mode", "feeding_mode"]
# VALID_MODES = ['count_trainable_weights', 'vector', 'gif', 'similarity', 'data_frame', 'psnr', 'memory_prep', 'measure_test_time']
# 
# Path: models/loss_functions.py
# def gradient_difference_loss(true, pred, alpha=2.0):
# def difference_gradient(image, vertical=True):
# def mean_squared_error(true, pred):
# def peak_signal_to_noise_ratio(true, pred):
# def kl_penalty(mu, sigma):
# def decoder_loss(frames_gen, frames_original, loss_fun):
# def decoder_psnr(frames_gen, frames_original):
# def composite_loss(original_frames, frames_pred, frames_reconst, loss_fun='mse',
#                    encoder_length=5, decoder_future_length=5,
#                    decoder_reconst_length=5, mu_latent=None, sigm_latent=None):


# Path: core/Model.py
import tensorflow as tf
import math
import numpy as np
import data_prep.model_input as input
from pprint import pprint
from settings import FLAGS, model
from models import loss_functions

          self.loss = average_losses(tower_losses)
          # concatenate outputs of towers to one large tensor each
          self.frames_pred = tf.unstack(tf.concat(1, frames_pred_list))
          self.frames_reconst = tf.unstack(tf.concat(1, frames_reconst_list))
          self.hidden_repr = tf.concat(0, hidden_repr_list)
          self.label = tf.concat(0, label_batch_list)
          self.metadata = tf.concat(0, metadata_batch_list)
          val_set = tf.concat(0, val_batch_list)

      self.add_image_summary(summary_prefix, val_set, FLAGS.encoder_length, FLAGS.decoder_future_length,
                             FLAGS.decoder_reconst_length)

      # evaluate frame predictions for storing on disk
      self.output_frames = self.frames_reconst + self.frames_pred  # join arrays of tensors


      self.summaries.append(tf.summary.scalar(summary_prefix + '_loss', self.loss))
      self.sum_op = tf.summary.merge(self.summaries)


class FeedingValidationModel(Model):
  def __init__(self, scope_name='feeding_model', reuse_scope=None):
    print("Constructing FeedingModel")
    with tf.variable_scope(scope_name, reuse=None):
      Model.__init__(self)

      assert reuse_scope is not None

      with tf.variable_scope(reuse_scope, reuse=True):
        "5D array of batch with videos - shape(batch_size, num_frames, frame_width, frame_higth, num_channels)"

        self.feed_batch = tf.placeholder(tf.float32, shape=(1, FLAGS.encoder_length, FLAGS.height, FLAGS.width, FLAGS.num_channels), name='feed_batch')