2

I use a model with a combinaison of GRu and Conv1D. When I want to fit the model I get an error in:

ValueError: Input 0 of layer "sequential_8" is incompatible with the layer: expected shape=(None, 223461, 5), found shape=(None, 5)

The shape of X_train is (223461, 5), whereas the y_train is (223461,)

This is my code:

verbose, epochs, batch_size = 0, 100, 64
n_timesteps, n_features, n_outputs = X_train.shape[0], X_train.shape[1], y_train.shape[0]
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu', input_shape=(n_timesteps,n_features)))
model.add(MaxPooling1D(pool_size=2))
model.add(GRU(64))
model.add(Dropout(0.4))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.4))
model.add(Dense(n_outputs, activation='softmax'))
opt = Adam(learning_rate=0.01)
model.compile(loss='categorical_crossentropy', optimizer=opt , metrics=['accuracy'])
model.summary()

The output of summary is:

Model: "sequential_8"
_____  Layer (type)                Output Shape              Param #
=====  conv1d_8 (Conv1D)           (None, 223459, 64)        1024
        max_pooling1d_8 (MaxPooling  (None, 111729, 64)       0           1D)

        gru_7 (GRU)                 (None, 64)                24960
        dropout_14 (Dropout)        (None, 64)                0
        flatten_6 (Flatten)         (None, 64)                0
        dense_14 (Dense)            (None, 128)               8320
        dropout_15 (Dropout)        (None, 128)               0
        dense_15 (Dense)            (None, 223461)            28826469

===== Total params: 28,860,773 Trainable params: 28,860,773 Non-trainable params: 0
_____

and here where I face the error:

model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, verbose=verbose)
_, accuracy = model.evaluate(X_test, y_test, batch_size=batch_size, verbose=0)

1 Answer 1

1

According to your model, your training data x_train and y_train is just a piece of data.

So your training data have to expand the dimension, like this:

X_train = X_train[None,:]
y_train = y_train[None,:]

Or use tensorflow function to do this :

X_train = tf.expand_dims(X_train, axis=0)
y_train = tf.expand_dims(y_train, axis=0)

The output shape of the model will be (1,223461)

If the output is not what you expected, it means your model design is wrong.

Sign up to request clarification or add additional context in comments.

7 Comments

This is the architecture that I want to use in my model is it right how I made it ? I want to make a binary classification of numerical data. And my classes are 0 and 1 . @AugustusHsu
I think the architecture is fine. But I want to check your dataset first. Dose the shape of X_train (223461, 5) mean you have 223461 data with 5 sequence and 1 dimension? or 1 data with 223461 sequence and 5 dimension?
yes yes you could check my colab here please . yes I want to mean 223461 sequence and 5 dimension . @Augustus
OK. Now you have X_train, but what do you want to predict? For example: If you want to predict the next timestamp of vmcategory. You need to set the n_timesteps and modify the X_train as (batch, n_timesteps, 5) to predict the vmcategory. Please check WindowGenerator to understand what does it do.
Also, I modify your code to this(I'm not sure if this is what you want.). It just is a sketch, you can change architecture, loss function or parameter(like n_timesteps).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.