I have a large working model where I'd like to change the last dense layer to a convolutional layer (with pooling and output). But I get the following error when using a cnn:
ValueError: Input 0 of layer conv1d_21 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 768]
This is how the last layers looked before trying to use a cnn:
dense = model.get_layer('NSP-Dense').output
outputs = keras.layers.Dense(len(100), activation='sigmoid')(dense)
This is how it looks when using the CNN and where the error occures (in the second line):
dense = model.get_layer('NSP-Dense').output
conv = keras.layers.Conv1D(filters=32, kernel_size=8, activation='relu')(dense)
pooling = keras.layers.MaxPooling1D(pool_size=2)(conv)
flatten = keras.layers.Flatten()(pooling)
mid_dense = keras.layers.Dense(400, activation='relu' )(flatten)
outputs = keras.layers.Dense(len(test_y[0]), activation='sigmoid')(mid_dense)
I read questions like this and this, but mine seems to be another issue, because the CNN is not the first layer but in the middle of the network.
The NSP-Dense Layer has an output shape of (None, 768). I tried to set the shape in the conv-layer to input_shape =(None, 768)
or input_shape =(None, 768, 1)
, but that did not resolve the issue. Does anyone have an idea?