# Path: core/Log.py
# class Stream:
# class Log(object):
#   def __init__(self, log, lvl):
#   def write(self, msg):
#   def flush(self):
#   def initialize(self, logs=[], verbosity=[], formatter=[]):
#   def write(self, msg):


import glob
import numpy as np
import tensorflow as tf
import pickle
from core.Log import log
    from tensorflow.contrib.framework import list_variables
    from tensorflow.contrib.framework import load_variable
    self.load_init_savers = None
    try:
      self.load_init = config.string("load_init", "")
      if self.load_init == "":
        self.load_init = []
      else:
        self.load_init = [self.load_init]
    except TypeError:
      self.load_init = config.string_list("load_init", [])

  def save_model(self, epoch):
    tf.gfile.MakeDirs(self.model_dir)
    self.tf_saver.save(self.session, self.model_dir + self.model, epoch)

  def try_load_weights(self):
    start_epoch = 0
    fn = None
    if self.load != "":
      fn = self.load.replace(".index", "")
    else:
      files = sorted(glob.glob(self.model_dir + self.model + "-*.index"))
      if len(files) > 0:
        if self.load_epoch_no > 0:
          epoch_string = str(self.load_epoch_no).zfill(8)
          files = [f for f in files if epoch_string in f]
        if len(files) > 0:
          fn = files[-1].replace(".index", "")

    if fn is not None:
      if self.build_networks:

# Path: core/Log.py
# class Stream:
# class Log(object):
#   def __init__(self, log, lvl):
#   def write(self, msg):
#   def flush(self):
#   def initialize(self, logs=[], verbosity=[], formatter=[]):
#   def write(self, msg):


# Path: core/Saver.py
import glob
import numpy as np
import tensorflow as tf
import pickle
from core.Log import log
    from tensorflow.contrib.framework import list_variables
    from tensorflow.contrib.framework import load_variable

    self.load_init_savers = None
    try:
      self.load_init = config.string("load_init", "")
      if self.load_init == "":
        self.load_init = []
      else:
        self.load_init = [self.load_init]
    except TypeError:
      self.load_init = config.string_list("load_init", [])

  def save_model(self, epoch):
    tf.gfile.MakeDirs(self.model_dir)
    self.tf_saver.save(self.session, self.model_dir + self.model, epoch)

  def try_load_weights(self):
    start_epoch = 0
    fn = None
    if self.load != "":
      fn = self.load.replace(".index", "")
    else:
      files = sorted(glob.glob(self.model_dir + self.model + "-*.index"))
      if len(files) > 0:
        if self.load_epoch_no > 0:
          epoch_string = str(self.load_epoch_no).zfill(8)
          files = [f for f in files if epoch_string in f]
        if len(files) > 0:
          fn = files[-1].replace(".index", "")

    if fn is not None:
      if self.build_networks:

        print("loading model from", fn, file=log.v1)