# Path: minos/model/parameters.py
# def is_custom_activation(name):
#     return name in custom_activations
# 
# def get_custom_activation(name):
#     return custom_activations.get(name, None)
# 
# def is_custom_layer(name):
#     return name in custom_layers
# 
# def get_custom_layer(name):
#     return custom_layers.get(name, None)
# 
# Path: minos/tf_utils.py
# def get_logical_device(physical_device):
#     if is_gpu_device(physical_device):
#         return '/gpu:0'
#     return physical_device
# 
# def cpu_device():
#     return '/cpu:0'


from copy import deepcopy
from keras.engine.topology import Input, Merge, merge
from keras.engine.training import Model
from keras.layers.core import Dense, Lambda
from keras.regularizers import L1L2Regularizer
from minos.model.parameters import is_custom_activation, get_custom_activation,\
    is_custom_layer, get_custom_layer
from minos.tf_utils import get_logical_device, cpu_device
import logging
import traceback
import keras
    import tensorflow as tf
    import tensorflow as tf

@author: julien
'''




class ModelBuilder(object):

    def __init__(self):
        pass

    def build(self, blueprint, device, compile_model=True):
        model = _build_model(blueprint, device)
        if compile_model:
            model.compile(
                optimizer=_build_optimizer(blueprint.training),
                loss=blueprint.training.objective.objective,
                metrics=[blueprint.training.metric.metric])
        return model


def _build_model(blueprint, device):
    if isinstance(device, list):
        return _build_multi_gpu_model(blueprint, device)
    else:
        return _build_single_device_model(blueprint, device)


def _build_single_device_model(blueprint, device):

# Path: minos/model/parameters.py
# def is_custom_activation(name):
#     return name in custom_activations
# 
# def get_custom_activation(name):
#     return custom_activations.get(name, None)
# 
# def is_custom_layer(name):
#     return name in custom_layers
# 
# def get_custom_layer(name):
#     return custom_layers.get(name, None)
# 
# Path: minos/tf_utils.py
# def get_logical_device(physical_device):
#     if is_gpu_device(physical_device):
#         return '/gpu:0'
#     return physical_device
# 
# def cpu_device():
#     return '/cpu:0'


# Path: minos/model/build.py
from copy import deepcopy
from keras.engine.topology import Input, Merge, merge
from keras.engine.training import Model
from keras.layers.core import Dense, Lambda
from keras.regularizers import L1L2Regularizer
from minos.model.parameters import is_custom_activation, get_custom_activation,\
    is_custom_layer, get_custom_layer
from minos.tf_utils import get_logical_device, cpu_device
import logging
import traceback
import keras
    import tensorflow as tf
    import tensorflow as tf


@author: julien
'''




class ModelBuilder(object):

    def __init__(self):
        pass

    def build(self, blueprint, device, compile_model=True):
        model = _build_model(blueprint, device)
        if compile_model:
            model.compile(
                optimizer=_build_optimizer(blueprint.training),
                loss=blueprint.training.objective.objective,
                metrics=[blueprint.training.metric.metric])
        return model


def _build_model(blueprint, device):
    if isinstance(device, list):
        return _build_multi_gpu_model(blueprint, device)
    else:
        return _build_single_device_model(blueprint, device)


def _build_single_device_model(blueprint, device):

    with tf.device(get_logical_device(device)):