ChihebTrabelsi / deep_complex_networks

Implementation related to the Deep Complex Networks
MIT License
734 stars 280 forks source link

GetReal not working #32

Open SpenceraM opened 6 years ago

SpenceraM commented 6 years ago

I am trying to add a complex dense layer to the deep network

def get_deep_convnet(window_size=4096, channels=2, output_size=84):
    print"start model"
    inputs = Input(shape=(window_size, channels))
    print "input shape is (", window_size,",", channels,")"
    outs = inputs 
    outs = (ComplexConv1D(
        16, 6, strides=2, padding='same',
        activation='linear',
        kernel_initializer='complex_independent'))(outs)
    outs = (ComplexBN(axis=-1))(outs)
    outs = (keras.layers.Activation('relu'))(outs)
    outs = (keras.layers.AveragePooling1D(pool_size=2, strides=2))(outs)
    outs = (ComplexConv1D(
        32, 3, strides=2, padding='same',
        activation='linear',
        kernel_initializer='complex_independent'))(outs)
    outs = (ComplexBN(axis=-1))(outs)
    outs = (keras.layers.Activation('relu'))(outs)
    outs = (keras.layers.AveragePooling1D(pool_size=2, strides=2))(outs)

    outs = (ComplexConv1D(
        64, 3, strides=1, padding='same',
        activation='linear',
        kernel_initializer='complex_independent'))(outs)
    outs = (ComplexBN(axis=-1))(outs)
    outs = (keras.layers.Activation('relu'))(outs)
    outs = (keras.layers.AveragePooling1D(pool_size=2, strides=2))(outs)

    outs = (ComplexConv1D(
        64, 3, strides=1, padding='same',
        activation='linear',
        kernel_initializer='complex_independent'))(outs)
    outs = (ComplexBN(axis=-1))(outs)
    outs = (keras.layers.Activation('relu'))(outs)
    outs = (keras.layers.AveragePooling1D(pool_size=2, strides=2))(outs)

    outs = (ComplexConv1D(
        128, 3, strides=1, padding='same',
        activation='relu',
        kernel_initializer='complex_independent'))(outs)
    outs = (ComplexConv1D(
        128, 3, strides=1, padding='same',
        activation='linear',
        kernel_initializer='complex_independent'))(outs)
    outs = (ComplexBN(axis=-1))(outs)
    outs = (keras.layers.Activation('relu'))(outs)
    outs = (keras.layers.AveragePooling1D(pool_size=2, strides=2))(outs)

    outs = (keras.layers.MaxPooling1D(pool_size=2))(outs)#com
    outs = (Permute([2, 1]))(outs)#com
    flattened = Flatten()(outs)

    dense = ComplexDense(2048, activation='relu')(flattened) #new from here
    predictions = ComplexDense(
        output_size, 
        activation='sigmoid',
        bias_initializer=Constant(value=-5))(dense)
    predictions = GetReal(predictions)
    model = Model(inputs=inputs, outputs=predictions)
    model.compile(optimizer=keras.optimizers.Adam(lr=1e-4),
                  loss='binary_crossentropy',
                  metrics=['accuracy'])
    print "end model"
    return model

The addition here is where I add the ComplexDense() and define it as 'dense'. The following error error is printed:

.. building model
.. complex network
.. using deep convnet
start model
input shape is ( 4096 , 2 )
Traceback (most recent call last):
  File "scripts/train.py", line 147, in <module>
    main(**parser.parse_args().__dict__)
  File "scripts/train.py", line 105, in main
    model = get_model(model, dataset.feature_dim)
  File "scripts/train.py", line 80, in get_model
    channels=feature_dim[1])
  File "/home/my_name/Dvlp/py2venvs/test_env/local/lib/python2.7/site-packages/musicnet/models/complex/__init__.py", line 107, in get_deep_convnet
    predictions = GetReal(predictions)
TypeError: __init__() takes exactly 1 argument (2 given)
enginsheer commented 6 years ago

In case it is useful to someone, change GetReal(predictions) to GetReal()(predictions)