src/core/layer.py
def stack_layers(inputs, layers, kernel_initializer='glorot_uniform'):
    '''
    Builds the architecture of the network by applying each layer specified in layers to inputs.

    inputs:     a dict containing input_types and input_placeholders for each key and value pair, respecively.
                for spectralnet, this means the input_types 'Unlabeled' and 'Orthonorm'*
    layers:     a list of dicts containing all layers to be used in the network, where each dict describes
                one such layer. each dict requires the key 'type'. all other keys are dependent on the layer
                type

    kernel_initializer: initialization configuration passed to keras (see keras initializers)

    returns:    outputs, a dict formatted in much the same way as inputs. it contains input_types and
                output_tensors for each key and value pair, respectively, where output_tensors are
                the outputs of the input_placeholders in inputs after each layer in layers is applied

    * this is necessary since spectralnet takes multiple inputs and performs special computations on the
      orthonorm layer
    '''
    outputs = dict()

    for key in inputs:
        outputs[key]=inputs[key]

    for layer in layers:
        # check for l2_reg argument
        l2_reg = layer.get('l2_reg')
        if l2_reg:
            l2_reg = l2(layer['l2_reg'])

        # create the layer
        if layer['type'] == 'softplus_reg':
            l = Dense(layer['size'], activation='softplus', kernel_initializer=kernel_initializer, kernel_regularizer=l2(0.001), name=layer.get('name'))
        elif layer['type'] == 'softplus':
            l = Dense(layer['size'], activation='softplus', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'softmax':
            l = Dense(layer['size'], activation='softmax', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'tanh':
            l = Dense(layer['size'], activation='tanh', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'relu':
            l = Dense(layer['size'], activation='relu', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'selu':
            l = Dense(layer['size'], activation='selu', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'Conv2D':
            l = Conv2D(layer['channels'], kernel_size=layer['kernel'], activation='relu', data_format='channels_last', kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'BatchNormalization':
            l = BatchNormalization(name=layer.get('name'))
        elif layer['type'] == 'MaxPooling2D':
            l = MaxPooling2D(pool_size=layer['pool_size'], data_format='channels_first', name=layer.get('name'))
        elif layer['type'] == 'Dropout':
            l = Dropout(layer['rate'], name=layer.get('name'))
        elif layer['type'] == 'Flatten':
            l = Flatten(name=layer.get('name'))
        elif layer['type'] == 'Orthonorm':
            l = Orthonorm(outputs['Orthonorm'], name=layer.get('name'));
        else:
            raise ValueError("Invalid layer type '{}'".format(layer['type']))

        # apply the layer to each input in inputs
        for k in outputs:
            outputs[k]=l(outputs[k])

    return outputs

    Builds the architecture of the network by applying each layer specified in layers to inputs.

    inputs:     a dict containing input_types and input_placeholders for each key and value pair, respecively.
                for spectralnet, this means the input_types 'Unlabeled' and 'Orthonorm'*
    layers:     a list of dicts containing all layers to be used in the network, where each dict describes
                one such layer. each dict requires the key 'type'. all other keys are dependent on the layer
                type

    kernel_initializer: initialization configuration passed to keras (see keras initializers)

    returns:    outputs, a dict formatted in much the same way as inputs. it contains input_types and
                output_tensors for each key and value pair, respectively, where output_tensors are
                the outputs of the input_placeholders in inputs after each layer in layers is applied

    * this is necessary since spectralnet takes multiple inputs and performs special computations on the
      orthonorm layer
    
Builds the architecture of the network by applying each layer specified in layers to inputs.
inputs:     a dict containing input_types and input_placeholders for each key and value pair, respecively.
for spectralnet, this means the input_types 'Unlabeled' and 'Orthonorm'
layers:     a list of dicts containing all layers to be used in the network, where each dict describes
one such layer. each dict requires the key 'type'. all other keys are dependent on the layer
type

initialization configuration passed to keras

outputs, a dict formatted in much the same way as inputs. it contains input_types and
output_tensors for each key and value pair, respectively, where output_tensors are
the outputs of the input_placeholders in inputs after each layer in layers is applied

this is necessary since spectralnet takes multiple inputs and performs special computations on the
orthonorm layer
Builds the architecture of the network by applying each layer specified in layers to inputs . inputs : a dict containing input_types and input_placeholders for each key and value pair respecively . for spectralnet this means the input_types ' Unlabeled ' and ' Orthonorm ' layers : a list of dicts containing all layers to be used in the network where each dict describes one such layer . each dict requires the key ' type ' . all other keys are dependent on the layer type initialization configuration passed to keras outputs a dict formatted in much the same way as inputs . it contains input_types and output_tensors for each key and value pair respectively where output_tensors are the outputs of the input_placeholders in inputs after each layer in layers is applied this is necessary since spectralnet takes multiple inputs and performs special computations on the orthonorm layer
def stack_layers(inputs, layers, kernel_initializer='glorot_uniform'):
    outputs = dict()
    for key in inputs:
        outputs[key]=inputs[key]
    for layer in layers:
        l2_reg = layer.get('l2_reg')
        if l2_reg:
            l2_reg = l2(layer['l2_reg'])
        if layer['type'] == 'softplus_reg':
            l = Dense(layer['size'], activation='softplus', kernel_initializer=kernel_initializer, kernel_regularizer=l2(0.001), name=layer.get('name'))
        elif layer['type'] == 'softplus':
            l = Dense(layer['size'], activation='softplus', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'softmax':
            l = Dense(layer['size'], activation='softmax', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'tanh':
            l = Dense(layer['size'], activation='tanh', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'relu':
            l = Dense(layer['size'], activation='relu', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'selu':
            l = Dense(layer['size'], activation='selu', kernel_initializer=kernel_initializer, kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'Conv2D':
            l = Conv2D(layer['channels'], kernel_size=layer['kernel'], activation='relu', data_format='channels_last', kernel_regularizer=l2_reg, name=layer.get('name'))
        elif layer['type'] == 'BatchNormalization':
            l = BatchNormalization(name=layer.get('name'))
        elif layer['type'] == 'MaxPooling2D':
            l = MaxPooling2D(pool_size=layer['pool_size'], data_format='channels_first', name=layer.get('name'))
        elif layer['type'] == 'Dropout':
            l = Dropout(layer['rate'], name=layer.get('name'))
        elif layer['type'] == 'Flatten':
            l = Flatten(name=layer.get('name'))
        elif layer['type'] == 'Orthonorm':
            l = Orthonorm(outputs['Orthonorm'], name=layer.get('name'));
        else:
            raise ValueError("Invalid layer type '{}'".format(layer['type']))
        for k in outputs:
            outputs[k]=l(outputs[k])
    return outputs
def stack_layers ( inputs , layers , kernel_initializer = 'glorot_uniform' ) : outputs = dict ( ) for key in inputs : outputs [ key ] = inputs [ key ] for layer in layers : l2_reg = layer . get ( 'l2_reg' ) if l2_reg : l2_reg = l2 ( layer [ 'l2_reg' ] ) if layer [ 'type' ] == 'softplus_reg' : l = Dense ( layer [ 'size' ] , activation = 'softplus' , kernel_initializer = kernel_initializer , kernel_regularizer = l2 ( 0.001 ) , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'softplus' : l = Dense ( layer [ 'size' ] , activation = 'softplus' , kernel_initializer = kernel_initializer , kernel_regularizer = l2_reg , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'softmax' : l = Dense ( layer [ 'size' ] , activation = 'softmax' , kernel_initializer = kernel_initializer , kernel_regularizer = l2_reg , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'tanh' : l = Dense ( layer [ 'size' ] , activation = 'tanh' , kernel_initializer = kernel_initializer , kernel_regularizer = l2_reg , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'relu' : l = Dense ( layer [ 'size' ] , activation = 'relu' , kernel_initializer = kernel_initializer , kernel_regularizer = l2_reg , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'selu' : l = Dense ( layer [ 'size' ] , activation = 'selu' , kernel_initializer = kernel_initializer , kernel_regularizer = l2_reg , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'Conv2D' : l = Conv2D ( layer [ 'channels' ] , kernel_size = layer [ 'kernel' ] , activation = 'relu' , data_format = 'channels_last' , kernel_regularizer = l2_reg , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'BatchNormalization' : l = BatchNormalization ( name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'MaxPooling2D' : l = MaxPooling2D ( pool_size = layer [ 'pool_size' ] , data_format = 'channels_first' , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'Dropout' : l = Dropout ( layer [ 'rate' ] , name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'Flatten' : l = Flatten ( name = layer . get ( 'name' ) ) elif layer [ 'type' ] == 'Orthonorm' : l = Orthonorm ( outputs [ 'Orthonorm' ] , name = layer . get ( 'name' ) ) ; else : raise ValueError ( "Invalid layer type '{}'" . format ( layer [ 'type' ] ) ) for k in outputs : outputs [ k ] = l ( outputs [ k ] ) return outputs
Builds the architecture of the network by applying each layer specified in layers to inputs.
Builds the architecture of the network by applying each layer specified in layers to inputs .
'''
    Builds the architecture of the network by applying each layer specified in layers to inputs.

    inputs:     a dict containing input_types and input_placeholders for each key and value pair, respecively.
                for spectralnet, this means the input_types 'Unlabeled' and 'Orthonorm'*
    layers:     a list of dicts containing all layers to be used in the network, where each dict describes
                one such layer. each dict requires the key 'type'. all other keys are dependent on the layer
                type

    kernel_initializer: initialization configuration passed to keras (see keras initializers)

    returns:    outputs, a dict formatted in much the same way as inputs. it contains input_types and
                output_tensors for each key and value pair, respectively, where output_tensors are
                the outputs of the input_placeholders in inputs after each layer in layers is applied

    * this is necessary since spectralnet takes multiple inputs and performs special computations on the
      orthonorm layer
    ''' # check for l2_reg argument # create the layer # apply the layer to each input in inputs
inputs
layers
kernel_initializer