# 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
            "don't match:", [(x.name, x.shape) for x in vars_shape_mismatch if "Adam" not in x.name], file=log.v1)
      vars_intersection = [x for x in vars_intersection if x not in vars_shape_mismatch]
    return tf.train.Saver(var_list=vars_intersection)

  def _initialize_deep_lab_rgb_weights(self, fn):
    vars_ = tf.global_variables()
    var_w = [x for x in vars_ if x.name == "xception_65/entry_flow/conv1_1/weights:0"]
    assert len(var_w) == 1, len(var_w)
    var_w = var_w[0]
    w = load_variable(fn, "xception_65/entry_flow/conv1_1/weights")
    val_new_w = self.session.run(var_w)
    val_new_w[:, :, :3, :] = w
    placeholder_w = tf.placeholder(tf.float32)
    assign_op_w = tf.assign(var_w, placeholder_w)
    self.session.run(assign_op_w, feed_dict={placeholder_w: val_new_w})


def load_wider_or_deeper_mxnet_model(model_path, session):
  params = pickle.load(open(model_path, "rb"), encoding="bytes")
  vars_ = tf.global_variables()

  model_name = model_path.split("/")[-1]
  if model_name.startswith("ilsvrc"):
    layer_mapping = {"res0": "res2a", "res1": "res2b1", "res2": "res2b2", "res3": "res3a", "res4": "res3b1",
                     "res5": "res3b2", "res6": "res4a", "res7": "res4b1", "res8": "res4b2", "res9": "res4b3",
                     "res10": "res4b4", "res11": "res4b5", "res12": "res5a", "res13": "res5b1", "res14": "res5b2",
                     "res15": "res6a", "res16": "res7a", "output": "linear1000", "conv0": "conv1a",
                     "collapse": "bn7"}
  elif model_name.startswith("ade"):
    layer_mapping = {"res0": "res2a", "res1": "res2b1", "res2": "res2b2", "res3": "res3a", "res4": "res3b1",

# 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

            "don't match:", [(x.name, x.shape) for x in vars_shape_mismatch if "Adam" not in x.name], file=log.v1)
      vars_intersection = [x for x in vars_intersection if x not in vars_shape_mismatch]
    return tf.train.Saver(var_list=vars_intersection)

  def _initialize_deep_lab_rgb_weights(self, fn):
    vars_ = tf.global_variables()
    var_w = [x for x in vars_ if x.name == "xception_65/entry_flow/conv1_1/weights:0"]
    assert len(var_w) == 1, len(var_w)
    var_w = var_w[0]
    w = load_variable(fn, "xception_65/entry_flow/conv1_1/weights")
    val_new_w = self.session.run(var_w)
    val_new_w[:, :, :3, :] = w
    placeholder_w = tf.placeholder(tf.float32)
    assign_op_w = tf.assign(var_w, placeholder_w)
    self.session.run(assign_op_w, feed_dict={placeholder_w: val_new_w})


def load_wider_or_deeper_mxnet_model(model_path, session):
  params = pickle.load(open(model_path, "rb"), encoding="bytes")
  vars_ = tf.global_variables()

  model_name = model_path.split("/")[-1]
  if model_name.startswith("ilsvrc"):
    layer_mapping = {"res0": "res2a", "res1": "res2b1", "res2": "res2b2", "res3": "res3a", "res4": "res3b1",
                     "res5": "res3b2", "res6": "res4a", "res7": "res4b1", "res8": "res4b2", "res9": "res4b3",
                     "res10": "res4b4", "res11": "res4b5", "res12": "res5a", "res13": "res5b1", "res14": "res5b2",
                     "res15": "res6a", "res16": "res7a", "output": "linear1000", "conv0": "conv1a",
                     "collapse": "bn7"}
  elif model_name.startswith("ade"):
    layer_mapping = {"res0": "res2a", "res1": "res2b1", "res2": "res2b2", "res3": "res3a", "res4": "res3b1",

                     "res5": "res3b2", "res6": "res4a", "res7": "res4b1", "res8": "res4b2", "res9": "res4b3",