Hi guys, I’m new to this topic, so please bear with me. I am trying to set up a CNN Network for the classification of sleep stages (5). I have come up with the following CNN structure:
ecg_input = Input(shape=(7680, 1), name='ecg')
activity_input = Input(shape=(1,), name='activity_normalized')
time_input = Input(shape=(1,), name='relative_time')
position_input = Input(shape=(1,), name='relative_position')
# Convolutional layers
# (7680, 1)
conv1 = Conv1D(32, 5, activation='relu', padding='same')(ecg_input)
conv1 = MaxPooling1D(2, padding='same')(conv1)
# (3840, 32)
conv2 = Conv1D(64, 5, activation='relu', padding='same')(conv1)
conv2 = MaxPooling1D(2, padding='same')(conv2)
# (1920, 64)
conv3 = Conv1D(128, 5, activation='relu', padding='same')(conv2)
conv3 = MaxPooling1D(2, padding='same')(conv3)
# (960, 128)
# Flatten layer
conv_flat = Flatten()(conv3)
# Dense layers
x = tf.keras.layers.concatenate([conv_flat, activity_input, time_input, position_input])
x = Dense(128, activation='relu')(x)
x = Dense(64, activation='relu')(x)
x = Dense(5, activation='softmax')(x)
# Output layer
output = x
# Create model
model = Model(inputs=[ecg_input, activity_input, time_input, position_input], outputs=output)
When fitting the Model, I am getting the following error:
ValueError: Exception encountered when calling Functional.call().
Input 0 of layer “dense” is incompatible with the layer: expected axis -1 of input shape to have value 122883, but received input with shape (None, 7810)
Arguments received by Functional.call():
- • inputs={‘ecg’: ‘tf.Tensor(shape=(None, 7680, 1), dtype=float32)’, ‘activity_normalized’: ‘tf.Tensor(shape=(None, 1), dtype=float32)’, ‘relative_time’: ‘tf.Tensor(shape=(None, 1), dtype=float32)’, ‘relative_position’: ‘tf.Tensor(shape=(None, 1), dtype=float32)’}*
- • training=True*
- • mask={‘ecg’: ‘None’, ‘activity_normalized’: ‘None’, ‘relative_time’: ‘None’, ‘relative_position’: ‘None’}ValueError: Exception encountered when calling Functional.call().*
Input 0 of layer “dense” is incompatible with the layer: expected axis -1 of input shape to have value 122883, but received input with shape (None, 7810)
Arguments received by Functional.call():
- • inputs={‘ecg’: ‘tf.Tensor(shape=(None, 7680, 1), dtype=float32)’, ‘activity_normalized’: ‘tf.Tensor(shape=(None, 1), dtype=float32)’, ‘relative_time’: ‘tf.Tensor(shape=(None, 1), dtype=float32)’, ‘relative_position’: ‘tf.Tensor(shape=(None, 1), dtype=float32)’}*
- • training=True*
- • mask={‘ecg’: ‘None’, ‘activity_normalized’: ‘None’, ‘relative_time’: ‘None’, ‘relative_position’: ‘None’}*
I can not understand why that happens, because even the model summary shows the expected shape.
So if you have an idea why this error accures and how to fix it or what to improve on the structure itself, please let me know! Any feedback is highly appreciated!