Skip to content Skip to sidebar Skip to footer

Building Cnn + Lstm In Keras For A Regression Problem. What Are Proper Shapes?

I am working on a regression problem where I feed a set of spectograms to CNN + LSTM - architecture in keras. My data is shaped as (n_samples, width, height, n_channels). The quest

Solution 1:

One possible solution is setting the LSTM input to be of shape (num_pixels, cnn_features). In your particular case, having a cnn with 32 filters, the LSTM would receive (256*256, 32)

cnn_features = 32

inp = tf.keras.layers.Input(shape=(256, 256, 3))
x = tf.keras.layers.Conv2D(filters=cnn_features,
                   activation='relu',
                   kernel_size=(2, 2),
                   padding='same')(inp)
x = tf.keras.layers.Reshape((256*256, cnn_features))(x)
x = tf.keras.layers.LSTM(units=128,
        activation='tanh',
        return_sequences=False)(x)
out = tf.keras.layers.Dense(1)(x)

Post a Comment for "Building Cnn + Lstm In Keras For A Regression Problem. What Are Proper Shapes?"