close

[Solved] ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors in Python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors Error Occurs?

Today I get the following error ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors in Python.

How To Solve ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors Error ?

  1. How To Solve ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors Error ?

    To Solve ValueError: Layer sequential_20 expects 1 inputs, but it received 2 input tensors Error it helped me when I changed:
    validation_data=[X_val, y_val] into validation_data=(X_val, y_val)
    Actually still wonder why?

Solution 1

it helped me when I changed:
validation_data=[X_val, y_val] into validation_data=(X_val, y_val)
Actually still wonder why?

Solution 2

Use validation_data=(img_test, img_test) instead of validation_data=[img_test, img_test]

Here the example with encoder and decoder combined together:

stacked_ae = keras.models.Sequential([
    keras.layers.Flatten(input_shape=[28, 28]),
    keras.layers.Dense(100, activation="selu"),
    keras.layers.Dense(30, activation="selu"),
    keras.layers.Dense(100, activation="selu"),
    keras.layers.Dense(28 * 28, activation="sigmoid"),
    keras.layers.Reshape([28, 28])
])

stacked_ae.compile(loss="binary_crossentropy",
                   optimizer=keras.optimizers.SGD(lr=1.5))

history = stacked_ae.fit(img_train, img_train, epochs=10,
                         validation_data=(img_test, img_test))

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment