# Path: selfsup/util.py
# class DummyDict(object):
#     def __init__(self):
#         pass
#     def __getitem__(self, item):
#         return DummyDict()
#     def __setitem__(self, item, value):
#         return DummyDict()
#     def get(self, item, default=None):
#         if default is None:
#             return DummyDict()
#         else:
#             return default
# 
# Path: selfsup/ops.py
# def max_pool(x, size, stride=None, name=None, info=DummyDict(), padding='SAME'):
# def avg_pool(x, size, stride=None, name=None, info=DummyDict(), padding='SAME'):
# def dropout(x, drop_prob, phase_test=None, name=None, info=DummyDict()):
# def scale(x, name=None, value=1.0):
# def inner(x, channels, info=DummyDict(), stddev=None,
#           activation=tf.nn.relu, name=None):
# def atrous_avg_pool(value, size, rate, padding, name=None, info=DummyDict()):
# def conv(x, channels, size=3, strides=1, activation=tf.nn.relu, name=None, padding='SAME',
#          info=DummyDict(), output_shape=None):
# def upconv(x, channels, size=3, strides=1, output_shape=None, activation=tf.nn.relu, name=None, padding='SAME',
#          info=DummyDict()):
#             W = tf.get_variable('weights', shape, dtype=tf.float32,
#                                 initializer=W_init)
#         W = tf.get_variable(name + '/weights', shape, dtype=tf.float32,
#                             initializer=W_init)
#         W = tf.get_variable(name + '/weights', shape, dtype=tf.float32,
#                             initializer=W_init)
# 
# Path: selfsup/caffe.py
# def to_caffe(tfW, name=None, shape=None, color_layer='', conv_fc_transitionals=None, info=DummyDict()):
# def from_caffe(cfW, name=None, color_layer='', conv_fc_transitionals=None, info=DummyDict()):
# def load_caffemodel(path, session, prefix='', ignore=set(),
#                     conv_fc_transitionals=None, renamed_layers=DummyDict(),
#                     color_layer='', verbose=False, pre_adjust_batch_norm=False):
#     def find_weights(name, which='weights'):
# def save_caffemodel(path, session, layers, prefix='',
#                     conv_fc_transitionals=None, color_layer='', verbose=False,
#                     save_batch_norm=False, lax_naming=False):
#     def find_weights(name, which='weights'):
#     def find_batch_norm(name, which='mean'):
#                     W = from_caffe(data[key]['0'], name=key, info=info,
#                                    conv_fc_transitionals=conv_fc_transitionals,
#                                    color_layer=color_layer)
#                         W = W.reshape(weights.get_shape().as_list())


import tensorflow as tf
import functools
import numpy as np
import sys
from selfsup.util import DummyDict
from selfsup import ops, caffe
        init_type = 'file'
        if name == 'conv1' and W2.shape[2] == 3:
            W2 = W2[:, :, ::-1]
            init_type += ':bgr-flipped'

        tr = {'fc6': (4096, 256, 6, 6)}
        tfW = caffe.from_caffe(W, name=name, conv_fc_transitionals=tr, color_layer='conv1')

        W = W2

        bn_name = 'batch_' + name
        if pre_adjust_batch_norm and bn_name in data:
            bn_data = data[bn_name]
            sigma = np.sqrt(1e-5 + bn_data['1'] / bn_data['2'])
            W /= sigma
            init_type += ':batch-adjusted'
        init = tf.constant_initializer(W)
        shape = W.shape
    else:
        init_type = 'init'
        init = tf.contrib.layers.variance_scaling_initializer()
    if info is not None:
        info[prefix + ':' + name + '/weights'] = init_type
    return init, shape


def _pretrained_alex_inner_weights_initializer(name, data, info=DummyDict(), pre_adjust_batch_norm=False, prefix=''):
    shape = None
    if name in data and '0' in data[name]:
        tr = {'fc6': (4096, 256, 6, 6)}

# Path: selfsup/util.py
# class DummyDict(object):
#     def __init__(self):
#         pass
#     def __getitem__(self, item):
#         return DummyDict()
#     def __setitem__(self, item, value):
#         return DummyDict()
#     def get(self, item, default=None):
#         if default is None:
#             return DummyDict()
#         else:
#             return default
# 
# Path: selfsup/ops.py
# def max_pool(x, size, stride=None, name=None, info=DummyDict(), padding='SAME'):
# def avg_pool(x, size, stride=None, name=None, info=DummyDict(), padding='SAME'):
# def dropout(x, drop_prob, phase_test=None, name=None, info=DummyDict()):
# def scale(x, name=None, value=1.0):
# def inner(x, channels, info=DummyDict(), stddev=None,
#           activation=tf.nn.relu, name=None):
# def atrous_avg_pool(value, size, rate, padding, name=None, info=DummyDict()):
# def conv(x, channels, size=3, strides=1, activation=tf.nn.relu, name=None, padding='SAME',
#          info=DummyDict(), output_shape=None):
# def upconv(x, channels, size=3, strides=1, output_shape=None, activation=tf.nn.relu, name=None, padding='SAME',
#          info=DummyDict()):
#             W = tf.get_variable('weights', shape, dtype=tf.float32,
#                                 initializer=W_init)
#         W = tf.get_variable(name + '/weights', shape, dtype=tf.float32,
#                             initializer=W_init)
#         W = tf.get_variable(name + '/weights', shape, dtype=tf.float32,
#                             initializer=W_init)
# 
# Path: selfsup/caffe.py
# def to_caffe(tfW, name=None, shape=None, color_layer='', conv_fc_transitionals=None, info=DummyDict()):
# def from_caffe(cfW, name=None, color_layer='', conv_fc_transitionals=None, info=DummyDict()):
# def load_caffemodel(path, session, prefix='', ignore=set(),
#                     conv_fc_transitionals=None, renamed_layers=DummyDict(),
#                     color_layer='', verbose=False, pre_adjust_batch_norm=False):
#     def find_weights(name, which='weights'):
# def save_caffemodel(path, session, layers, prefix='',
#                     conv_fc_transitionals=None, color_layer='', verbose=False,
#                     save_batch_norm=False, lax_naming=False):
#     def find_weights(name, which='weights'):
#     def find_batch_norm(name, which='mean'):
#                     W = from_caffe(data[key]['0'], name=key, info=info,
#                                    conv_fc_transitionals=conv_fc_transitionals,
#                                    color_layer=color_layer)
#                         W = W.reshape(weights.get_shape().as_list())


# Path: selfsup/model/alex.py
import tensorflow as tf
import functools
import numpy as np
import sys
from selfsup.util import DummyDict
from selfsup import ops, caffe

        init_type = 'file'
        if name == 'conv1' and W2.shape[2] == 3:
            W2 = W2[:, :, ::-1]
            init_type += ':bgr-flipped'

        tr = {'fc6': (4096, 256, 6, 6)}
        tfW = caffe.from_caffe(W, name=name, conv_fc_transitionals=tr, color_layer='conv1')

        W = W2

        bn_name = 'batch_' + name
        if pre_adjust_batch_norm and bn_name in data:
            bn_data = data[bn_name]
            sigma = np.sqrt(1e-5 + bn_data['1'] / bn_data['2'])
            W /= sigma
            init_type += ':batch-adjusted'
        init = tf.constant_initializer(W)
        shape = W.shape
    else:
        init_type = 'init'
        init = tf.contrib.layers.variance_scaling_initializer()
    if info is not None:
        info[prefix + ':' + name + '/weights'] = init_type
    return init, shape


def _pretrained_alex_inner_weights_initializer(name, data, info=DummyDict(), pre_adjust_batch_norm=False, prefix=''):
    shape = None
    if name in data and '0' in data[name]:
        tr = {'fc6': (4096, 256, 6, 6)}

        W = caffe.from_caffe(data[name]['0'], name=name, conv_fc_transitionals=tr, color_layer='conv1')