def ufcnn_model_deconv(sequence_length=5000,
                       features=4,
                       nb_filter=150,
                       filter_length=5,
                       output_dim=1,
                       optimizer='adagrad',
                       loss='mse',
                       regression = False,
                       class_mode=None,
                       activation="softplus",
                       init="lecun_uniform"):
    #model = Graph()

    #model.add_input(name='input', input_shape=(None, features))

    main_input = Input(name='input', shape=(None, features))

    #########################################################

    #model.add_node(ZeroPadding1D(2), name='input_padding', input='input') # to avoid lookahead bias

    input_padding = (ZeroPadding1D(2))(main_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(activation), name='relu1', input='conv1')

    conv1 = Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='valid', init=init, input_shape=(sequence_length, features))(input_padding)
    relu1 = (Activation(activation))(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(activation), name='relu2', input='conv2')

    conv2 = (Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init))(relu1)
    relu2 = (Activation(activation))(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(activation), name='relu3', input='conv3')


    conv3 = (Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init))(relu2)
    relu3 = (Activation(activation))(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(activation), name='relu4', input='conv4')

    conv4 = (Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init))(relu3)
    relu4 = (Activation(activation))(conv4)

    #########################################################
    #model.add_node(Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init), name='conv5', input='relu4')
    #model.add_node(Activation(activation), name='relu5', input='conv5')

    conv5 = (Convolution1D(nb_filter=nb_filter, filter_length=filter_length, border_mode='same', init=init))(relu4)
    relu5 = (Activation(activation))(conv5)

    #########################################################
    #model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
    #                 name='conv6',
    #                 inputs=['relu3', 'relu5'],
    #                 merge_mode='concat', concat_axis=-1)
    #model.add_node(Activation(activation), name='relu6', input='conv6')


    conv6 = merge([relu3, relu5], mode='concat', concat_axis=1)
    relu6 = (Activation(activation))(conv6)

    #########################################################
    #model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
    #                 name='conv7',
    #                 inputs=['relu2', 'relu6'],
    #                 merge_mode='concat', concat_axis=-1)
    #model.add_node(Activation(activation), name='relu7', input='conv7')

    conv7 = merge([relu2, relu6], mode='concat', concat_axis=1)
    relu7 = (Activation(activation))(conv7)

    #########################################################
    #model.add_node(Convolution1D(nb_filter=nb_filter,filter_length=filter_length, border_mode='same', init=init),
    #                 name='conv8',
    #                 inputs=['relu1', 'relu7'],
    #                 merge_mode='concat', concat_axis=-1)
    #model.add_node(Activation(activation), name='relu8', input='conv8')

    conv8 = merge([relu1, relu7], mode='concat', concat_axis=1)
    relu8 = (Activation(activation))(conv8)

    #########################################################
    if regression:
        #########################################################
        #model.add_node(Convolution1D(nb_filter=output_dim, filter_length=sequence_length, border_mode='same', init=init), name='conv9', input='relu8')
        #model.add_output(name='output', input='conv9')


        conv9 = Convolution1D(nb_filter=output_dim, filter_length=sequence_length, border_mode='same', init=init)(relu8)
        output = conv9
        #main_output = conv9.output

    else:
        #model.add_node(Convolution1D(nb_filter=output_dim, filter_length=sequence_length, border_mode='same', init=init), name='conv9', input='relu8')
        #model.add_node(Activation('softmax'), name='activation', input='conv9')
        #model.add_output(name='output', input='activation')

        conv9 = Convolution1D(nb_filter=output_dim, filter_length=sequence_length, border_mode='same', init=init)(relu8)
        activation = (Activation('softmax'))(conv9)
        #main_output = activation.output
        output = activation

    #model.compile(optimizer=optimizer, loss={'output': loss})

    model = Model(input=main_input, output=output)
    model.compile(optimizer=optimizer, loss=loss)

    return model