OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Layer "sequential_29" expects 1 input(s), but it received 3 input tensors

  • Thread starter Thread starter Adriana
  • Start date Start date
A

Adriana

Guest
I am trying to use GridSearchCV on a trained model. But the following error occurs:

Layer "sequential_29" expects 1 input(s), but it received 3 input tensors. Inputs received: [<tf.Tensor: shape=(), dtype=int32, numpy=100>, <tf.Tensor: shape=(), dtype=int32, numpy=100>, <tf.Tensor: shape=(), dtype=int32, numpy=1>]

I have searched everywhere but I didn't succeed to run GridSearchCV.

My model looks like :

Code:
def cnn_model(size):
    model = Sequential()
    model.add(Conv2D(16,3,input_shape=size, activation='relu', padding='same'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Conv2D(32,3,input_shape=size, activation='relu', padding='same'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Conv2D(16,3,input_shape=size, activation='relu', padding='same'))
    model.add(Dropout(0.2))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Flatten())
    model.add(Dense(100, activation='relu'))
    model.add(Dense(1, activation='sigmoid'))
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    model.compile('adam', loss=tf.losses.BinaryCrossentropy(), metrics=['accuracy'])
    #print(model.summary())
    return model

I trained the model with "fit" function and a shape of (16149, 100, 100, 1) for X_train. And there isn't any problem.

Now when I tried to run GridSearchCV with the same data :

Code:
model_wopad2 = KerasClassifier(lambda:model_wopad(IMAGE_SIZE), verbose = 1)
grid = GridSearchCV(estimator = model_wopad2, param_grid = param_grid, scoring="accuracy", verbose = 1)
grid_results = grid.fit(X_train,y_train, validation_data=(X_val, Y_val))

I obtain the above error.

Do you have any idea of how to reshape the data (or other) in order to run this function ?

I also saw that we can create our own GridSearch function but I didn't succeed either

I already tried to change the shape of the model in the 'KerasClassifier' function. I tried to reshape my X_train data but didn't know what's the problem in the actual shape
<p>I am trying to use GridSearchCV on a trained model. But the following error occurs:</p>
<blockquote>
<p>Layer "sequential_29" expects 1 input(s), but it received 3 input tensors. Inputs received: [<tf.Tensor: shape=(), dtype=int32, numpy=100>, <tf.Tensor: shape=(), dtype=int32, numpy=100>, <tf.Tensor: shape=(), dtype=int32, numpy=1>]</p>
</blockquote>
<p>I have searched everywhere but I didn't succeed to run GridSearchCV.</p>
<p>My model looks like :</p>
<pre><code>def cnn_model(size):
model = Sequential()
model.add(Conv2D(16,3,input_shape=size, activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(32,3,input_shape=size, activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(16,3,input_shape=size, activation='relu', padding='same'))
model.add(Dropout(0.2))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.compile('adam', loss=tf.losses.BinaryCrossentropy(), metrics=['accuracy'])
#print(model.summary())
return model
</code></pre>
<p>I trained the model with "fit" function and a shape of (16149, 100, 100, 1) for X_train. And there isn't any problem.</p>
<p>Now when I tried to run GridSearchCV with the same data :</p>
<pre><code>model_wopad2 = KerasClassifier(lambda:model_wopad(IMAGE_SIZE), verbose = 1)
grid = GridSearchCV(estimator = model_wopad2, param_grid = param_grid, scoring="accuracy", verbose = 1)
grid_results = grid.fit(X_train,y_train, validation_data=(X_val, Y_val))
</code></pre>
<p>I obtain the above error.</p>
<p>Do you have any idea of how to reshape the data (or other) in order to run this function ?</p>
<p>I also saw that we can create our own GridSearch function but I didn't succeed either</p>
<p>I already tried to change the shape of the model in the 'KerasClassifier' function.
I tried to reshape my X_train data but didn't know what's the problem in the actual shape</p>
 

Latest posts

Top