# Path: deep_architect/contrib/misc/search_spaces/tensorflow/common.py
# D = hp.Discrete
# 
# def siso_tensorflow_module(name, compile_fn, name_to_hyperp, scope=None):
#     return htf.TensorflowModule(name, compile_fn, name_to_hyperp, ['in'],
#                                 ['out'], scope).get_io()


from deep_architect.contrib.misc.search_spaces.tensorflow.common import D, siso_tensorflow_module
import deep_architect.contrib.misc.search_spaces.tensorflow.dnn as dnn
import deep_architect.modules as mo
import tensorflow as tf
import numpy as np


def kaiming2015delving_initializer_conv(gain=1.0):

    def init_fn(shape):
        n = np.product(shape)
        stddev = gain * np.sqrt(2.0 / n)
        init_vals = tf.random_normal(shape, 0.0, stddev)
        return init_vals

    return init_fn


def conv2d(h_num_filters, h_filter_width, h_stride, h_use_bias):

    def compile_fn(di, dh):
        conv_op = tf.layers.Conv2D(dh['num_filters'], (dh['filter_width'],) * 2,
                                   (dh['stride'],) * 2,
                                   use_bias=dh['use_bias'],
                                   padding='SAME')

        def forward_fn(di):
            return {'out': conv_op(di['in'])}

        return forward_fn

    return siso_tensorflow_module(
        'Conv2D', compile_fn, {

# Path: deep_architect/contrib/misc/search_spaces/tensorflow/common.py
# D = hp.Discrete
# 
# def siso_tensorflow_module(name, compile_fn, name_to_hyperp, scope=None):
#     return htf.TensorflowModule(name, compile_fn, name_to_hyperp, ['in'],
#                                 ['out'], scope).get_io()


# Path: deep_architect/contrib/misc/search_spaces/tensorflow/cnn2d.py
from deep_architect.contrib.misc.search_spaces.tensorflow.common import D, siso_tensorflow_module
import deep_architect.contrib.misc.search_spaces.tensorflow.dnn as dnn
import deep_architect.modules as mo
import tensorflow as tf
import numpy as np



def kaiming2015delving_initializer_conv(gain=1.0):

    def init_fn(shape):
        n = np.product(shape)
        stddev = gain * np.sqrt(2.0 / n)
        init_vals = tf.random_normal(shape, 0.0, stddev)
        return init_vals

    return init_fn


def conv2d(h_num_filters, h_filter_width, h_stride, h_use_bias):

    def compile_fn(di, dh):
        conv_op = tf.layers.Conv2D(dh['num_filters'], (dh['filter_width'],) * 2,
                                   (dh['stride'],) * 2,
                                   use_bias=dh['use_bias'],
                                   padding='SAME')

        def forward_fn(di):
            return {'out': conv_op(di['in'])}

        return forward_fn

    return siso_tensorflow_module(
        'Conv2D', compile_fn, {

            'num_filters': h_num_filters,