# 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
    elif val.ndim == 4:
      val = np.moveaxis(val, [0, 1, 2, 3], [3, 2, 0, 1])
    else:
      assert False, val.ndim
    var = var_dict[k]
    if var.get_shape() == val.shape:
      placeholder = tf.placeholder(tf.float32)
      op = tf.assign(var, placeholder)
      feed_dict[placeholder] = val
      ops.append(op)
    elif k.startswith("conv0"):
      print("warning, sizes for", k, "do not match, initializing matching part assuming the first 3 dimensions are RGB",
            file=log.v1)
      val_new = session.run(var)
      val_new[..., :3, :] = val
      placeholder = tf.placeholder(tf.float32)
      op = tf.assign(var, placeholder)
      feed_dict[placeholder] = val_new
      ops.append(op)
    else:
      print("skipping", k, "since the shapes do not match:", var.get_shape(), "and", val.shape, file=log.v1)
  session.run(ops, feed_dict=feed_dict)
  print("done loading mxnet model", file=log.v1)


def create_mxnet_dict(layer_mapping, var_dict):
  mxnet_dict = {}
  for vn in var_dict:
    sp = vn.split("/")
    if sp[0] not in layer_mapping:

# 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

    elif val.ndim == 4:
      val = np.moveaxis(val, [0, 1, 2, 3], [3, 2, 0, 1])
    else:
      assert False, val.ndim
    var = var_dict[k]
    if var.get_shape() == val.shape:
      placeholder = tf.placeholder(tf.float32)
      op = tf.assign(var, placeholder)
      feed_dict[placeholder] = val
      ops.append(op)
    elif k.startswith("conv0"):
      print("warning, sizes for", k, "do not match, initializing matching part assuming the first 3 dimensions are RGB",
            file=log.v1)
      val_new = session.run(var)
      val_new[..., :3, :] = val
      placeholder = tf.placeholder(tf.float32)
      op = tf.assign(var, placeholder)
      feed_dict[placeholder] = val_new
      ops.append(op)
    else:
      print("skipping", k, "since the shapes do not match:", var.get_shape(), "and", val.shape, file=log.v1)
  session.run(ops, feed_dict=feed_dict)
  print("done loading mxnet model", file=log.v1)


def create_mxnet_dict(layer_mapping, var_dict):
  mxnet_dict = {}
  for vn in var_dict:
    sp = vn.split("/")
    if sp[0] not in layer_mapping:

      print("warning,", vn, "not found in mxnet model", file=log.v1)