Skip to content

Instantly share code, notes, and snippets.

@lukovkin
Last active June 20, 2016 02:06
Show Gist options
  • Save lukovkin/8d8d9994ecc20914b884 to your computer and use it in GitHub Desktop.
Save lukovkin/8d8d9994ecc20914b884 to your computer and use it in GitHub Desktop.
Sample of FCN model
model = Graph()
model.add_input(name='input', input_shape=(sequence_length, features))
#########################################################
model.add_node(ZeroPadding1D(2), name='input_padding', input='input') # to avoid lookahead bias
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='valid', init=init), name='conv1', input='input_padding')
model.add_node(ParametricSoftplus(), name='relu1', input='conv1')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv2', input='relu1')
model.add_node(ParametricSoftplus(), name='relu2', input='conv2')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv3', input='relu2')
model.add_node(ParametricSoftplus(), name='relu3', input='conv3')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv4', input='relu3')
model.add_node(ParametricSoftplus(), name='relu4', input='conv4')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
name='conv5',
inputs=['relu2', 'relu4'],
merge_mode='concat', concat_axis=-1)
model.add_node(ParametricSoftplus(), name='relu5', input='conv5')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
name='conv6',
inputs=['relu1', 'relu5'],
merge_mode='concat', concat_axis=-1)
model.add_node(ParametricSoftplus(), name='relu6', input='conv6')
#########################################################
model.add_node(Convolution1D(nb_filter=output_dim, filter_length=sequence_length, border_mode='same', init=init), name='conv7', input='relu6')
model.add_node(Activation('sigmoid'), name='activation', input='conv7')
model.add_output(name='output', input='activation')
model.compile(optimizer=optimizer, loss={'output': loss})
model = Graph()
model.add_input(name='input', input_shape=(None, features))
#########################################################
model.add_node(ZeroPadding1D(2), name='input_padding', input='input') # to avoid lookahead bias
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='valid', init=init, input_shape=(sequence_length, features)), name='conv1', input='input_padding')
model.add_node(Activation('relu'), name='relu1', input='conv1')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv2', input='relu1')
model.add_node(Activation('relu'), name='relu2', input='conv2')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv3', input='relu2')
model.add_node(Activation('relu'), name='relu3', input='conv3')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv4', input='relu3')
model.add_node(Activation('relu'), name='relu4', input='conv4')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
name='conv5',
inputs=['relu2', 'relu4'],
merge_mode='concat', concat_axis=-1)
model.add_node(Activation('relu'), name='relu5', input='conv5')
#########################################################
model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
name='conv6',
inputs=['relu1', 'relu5'],
merge_mode='concat', concat_axis=-1)
model.add_node(Activation('relu'), name='relu6', input='conv6')
model.add_node(Convolution1D(nb_filter=output_dim, filter_length=sequence_length, border_mode='same', init=init), name='conv7', input='relu6')
model.add_node(Activation('sigmoid'), name='activation', input='conv7')
model.add_output(name='output', input='activation')
model.compile(optimizer=optimizer, loss={'output': loss})
input : <class 'keras.layers.core.Layer'> : (None, 500, 4) : (None, 500, 4)
input_padding : <class 'keras.layers.convolutional.ZeroPadding1D'> : (None, 500, 4) : (None, 504, 4)
conv1 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 504, 4) : (None, 500, 150)
relu1 : <class 'keras.layers.advanced_activations.ParametricSoftplus'> : (None, 500, 150) : (None, 500, 150)
conv2 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 500, 150) : (None, 500, 150)
relu2 : <class 'keras.layers.advanced_activations.ParametricSoftplus'> : (None, 500, 150) : (None, 500, 150)
conv3 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 500, 150) : (None, 500, 150)
relu3 : <class 'keras.layers.advanced_activations.ParametricSoftplus'> : (None, 500, 150) : (None, 500, 150)
conv4 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 500, 150) : (None, 500, 150)
relu4 : <class 'keras.layers.advanced_activations.ParametricSoftplus'> : (None, 500, 150) : (None, 500, 150)
conv5 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 500, 300) : (None, 500, 150)
relu5 : <class 'keras.layers.advanced_activations.ParametricSoftplus'> : (None, 500, 150) : (None, 500, 150)
conv6 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 500, 300) : (None, 500, 150)
relu6 : <class 'keras.layers.advanced_activations.ParametricSoftplus'> : (None, 500, 150) : (None, 500, 150)
conv7 : <class 'keras.layers.convolutional.Convolution1D'> : (None, 500, 150) : (None, 500, 3)
activation : <class 'keras.layers.core.Activation'> : (None, 500, 3) : (None, 500, 3)
output : <class 'keras.layers.core.Activation'> : (None, 500, 3) : (None, 500, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment