I want to implement a CNN model with Keras. My data has the shape NHW, respectivly (N, 40, 4). You can see it as an gray-scale Image of size 40x4. I want to stride the kernel which has size (3, 4) just over the Height-axis, so it should compute the result for 3 full rows. As you can see there are no Channels (which means I have a 3-Tensor), but Keras Conv2D layer requires a shape of NHWC (4-Tensor). I tried it anyhow by the following command, but it results obviously in an error:
tf.keras.layers.Conv2D(8, kernel_size=(3, 4), activation="relu", input_shape=(40, 4)
ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (1, 40, 4)
Therefore, I tried to append a new axis to my input data, which shall represent the channel.
np.expand_dims(input_data, axis=3)
...
tf.keras.layers.Conv2D(1, kernel_size=(3, 4), activation="relu", input_shape=(40, 4, 1), data_format="channels_last")
This results in a different error message:
ValueError: Shape mismatch: The shape of labels (received (1,)) should equal the shape of logits except for the last dimension (received (40, 5)).
Do you know how I can implement such a CNN model with an input shape of NHW?