Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14040

ValueError: Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 128, 1280), found shape=(None, 1280)

$
0
0

I am building a 1d CNN model which can input 10 second long ecg frames and detect a specific heart disorder. I have 130,464 training data and 32,616 testing data. My input data is of the shape (num_samples, 1280)

from tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Conv1D, MaxPooling1D, Flatten, Dense, BatchNormalization,    RepeatVectormodel = Sequential()model.add(Conv1D(filters=512, kernel_size=8, activation='relu', input_shape=(128, 1280), name="1_conv1d"))model.add(BatchNormalization())model.add(MaxPooling1D(pool_size=2))# model.add(Conv1D(filters=256, kernel_size=6, activation='relu', input_shape=(32, 1280), name="2_conv1d"))# model.add(BatchNormalization())# model.add(MaxPooling1D(pool_size=2))# model.add(Conv1D(filters=128, kernel_size=4, activation='relu', input_shape=(32, 1280)))# model.add(Conv1D(filters=32, kernel_size=2, activation='relu', input_shape=(32, 1), name="3_conv1d"))model.add(Flatten())model.add(Dense(units=128, activation='relu'))model.add(Dense(units=1, activation='sigmoid'))model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])# train_data = tf.data.Dataset.from_tensor_slices((X_train, Y_train))# model.fit(train_data, epochs=4, batch_size=1024)model.fit(X_train, Y_train, epochs=4, batch_size=1024)test_loss, test_accuracy = model.evaluate(X_test, Y_test)

I had commented out a lot of the layers hoping that it would help me pinpoint the error. However, the error thrown is the same.

ValueError: in user code:File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1401, in train_function  *    return step_function(self, iterator)File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1384, in step_function  **    outputs = model.distribute_strategy.run(run_step, args=(data,))File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1373, in run_step  **    outputs = model.train_step(data)File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1150, in train_step    y_pred = self(x, training=True)File "/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler    raise e.with_traceback(filtered_tb) from NoneFile "/usr/local/lib/python3.10/dist-packages/keras/src/engine/input_spec.py", line 298, in   assert_input_compatibility    raise ValueError(ValueError: Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 128, 1280), found shape=(None, 1280)

I followed the advice from previous questions posted of similar issues. It didn't help. I also tried changing the batch sizes and input shapes, didn't help.

My next step is to try reshaping the input since the error says it received (None, 1280) instead of (None, 128, 1280). But I don't know how to. Any help on this?


Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>