# Path: network/Util.py
# def create_batch_norm_vars(n_out, tower_setup, scope_name="bn"):
#   with tf.device(tower_setup.variable_device), tf.variable_scope(scope_name):
#     initializer_zero = tf.constant_initializer(0.0, dtype=tf.float32)
#     beta = tf.get_variable("beta", [n_out], tf.float32, initializer_zero)
#     initializer_gamma = tf.constant_initializer(1.0, dtype=tf.float32)
#     gamma = tf.get_variable("gamma", [n_out], tf.float32, initializer_gamma)
#     mean_ema = tf.get_variable("mean_ema", [n_out], tf.float32, initializer_zero, trainable=False)
#     var_ema = tf.get_variable("var_ema", [n_out], tf.float32, initializer_zero, trainable=False)
#     return beta, gamma, mean_ema, var_ema


import tensorflow as tf
import numpy as np
from tensorflow.python.training import moving_averages
from network.Util import create_batch_norm_vars



class Layer:
  BATCH_NORM_DECAY_DEFAULT = 0.95
  BATCH_NORM_EPSILON = 1e-5
  L2_DEFAULT = 1e-4

  def __init__(self):
    self.summaries = []
    self.regularizers = []
    self.losses = []
    self.update_ops = []
    self.outputs = []
    self.placeholders = []
    self.measures = {}
    self.extractions = {}
    self.n_params = 0

  def add_scalar_summary(self, op, name):
    summary = tf.summary.scalar(name, op)
    self.summaries.append(summary)

  def add_image_summary(self, im, name):
    summary = tf.summary.image(name, im)
    self.summaries.append(summary)

  def create_and_apply_batch_norm(self, inp, n_features, decay, tower_setup, scope_name="bn", freeze_batchnorm_override=None):

# Path: network/Util.py
# def create_batch_norm_vars(n_out, tower_setup, scope_name="bn"):
#   with tf.device(tower_setup.variable_device), tf.variable_scope(scope_name):
#     initializer_zero = tf.constant_initializer(0.0, dtype=tf.float32)
#     beta = tf.get_variable("beta", [n_out], tf.float32, initializer_zero)
#     initializer_gamma = tf.constant_initializer(1.0, dtype=tf.float32)
#     gamma = tf.get_variable("gamma", [n_out], tf.float32, initializer_gamma)
#     mean_ema = tf.get_variable("mean_ema", [n_out], tf.float32, initializer_zero, trainable=False)
#     var_ema = tf.get_variable("var_ema", [n_out], tf.float32, initializer_zero, trainable=False)
#     return beta, gamma, mean_ema, var_ema


# Path: network/Layer.py
import tensorflow as tf
import numpy as np
from tensorflow.python.training import moving_averages
from network.Util import create_batch_norm_vars




class Layer:
  BATCH_NORM_DECAY_DEFAULT = 0.95
  BATCH_NORM_EPSILON = 1e-5
  L2_DEFAULT = 1e-4

  def __init__(self):
    self.summaries = []
    self.regularizers = []
    self.losses = []
    self.update_ops = []
    self.outputs = []
    self.placeholders = []
    self.measures = {}
    self.extractions = {}
    self.n_params = 0

  def add_scalar_summary(self, op, name):
    summary = tf.summary.scalar(name, op)
    self.summaries.append(summary)

  def add_image_summary(self, im, name):
    summary = tf.summary.image(name, im)
    self.summaries.append(summary)

  def create_and_apply_batch_norm(self, inp, n_features, decay, tower_setup, scope_name="bn", freeze_batchnorm_override=None):

    beta, gamma, moving_mean, moving_var = create_batch_norm_vars(n_features, tower_setup, scope_name)