# 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
    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)):
        inputs = Input(shape=(blueprint.layout.input_size,))
        row_input = inputs
        for row in blueprint.layout.rows:
            row_input = _build_row_model(row_input, row)
        final_layer_input = _maybe_merge_inputs(row_input)
        predictions = Dense(
            blueprint.layout.output_size,
            activation=blueprint.layout.output_activation)(final_layer_input)
        return Model(input=inputs, output=predictions)


class MultiGpuModel(Model):

    def __init__(self, model, model_input, model_output):
        super().__init__(input=model_input, output=model_output)
        self.model = model

    def save(self, filepath, overwrite=True):
        self.model.save(filepath=filepath, overwrite=overwrite)


def _build_multi_gpu_model(blueprint, devices):

# 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

    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)):
        inputs = Input(shape=(blueprint.layout.input_size,))
        row_input = inputs
        for row in blueprint.layout.rows:
            row_input = _build_row_model(row_input, row)
        final_layer_input = _maybe_merge_inputs(row_input)
        predictions = Dense(
            blueprint.layout.output_size,
            activation=blueprint.layout.output_activation)(final_layer_input)
        return Model(input=inputs, output=predictions)


class MultiGpuModel(Model):

    def __init__(self, model, model_input, model_output):
        super().__init__(input=model_input, output=model_output)
        self.model = model

    def save(self, filepath, overwrite=True):
        self.model.save(filepath=filepath, overwrite=overwrite)


def _build_multi_gpu_model(blueprint, devices):

    model = _build_single_device_model(blueprint, cpu_device())