2
hist_model = Model.fit(x=train_average, y=train_zero,
                  epochs=5,
                  batch_size=256,
                  verbose = 2, 
                  validation_data=(train_average, validate))

I am working Autoencoder model for recommendation. i get this error the error below on validation_data, when i run the above code. am using the google colab.

 /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1298 test_function  *
        return step_function(self, iterator)
    /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1282 run_step  *
        outputs = model.test_step(data)
    /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:1241 test_step  *
        y_pred = self(x, training=False)
    /usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py:989 __call__  *
        input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
    /usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py:197 assert_input_compatibility  *
        raise ValueError('Layer ' + layer_name + ' expects ' +

    ValueError: Layer model_1 expects 1 input(s), but it received 2 input tensors.

I need help.

4 Answers 4

1

Here is the model


# Convert data types from int64 to float32 to use as tensor inputs for Keras model
train_zero = tf.convert_to_tensor(train_zero, dtype=tf.float32)
train_one = tf.convert_to_tensor(train_one, dtype=tf.float32)
train_two = tf.convert_to_tensor(train_two, dtype=tf.float32)
#train_three = tf.convert_to_tensor(train_three, dtype=tf.float32)
#train_four = tf.convert_to_tensor(train_four, dtype=tf.float32)
#train_five = tf.convert_to_tensor(train_five, dtype=tf.float32)
train_average = tf.convert_to_tensor(train_average, dtype=tf.float32)
validate = tf.convert_to_tensor(validate, dtype=tf.float32)
test = tf.convert_to_tensor(test, dtype=tf.float32)



def AutoRec(X, reg, first_activation, last_activation):
  
    input_layer = x = Input(shape=(X.shape[1],), name='UserRating')
    x = Dense(500, activation=first_activation, name='LatentSpace', kernel_regularizer=regularizers.l2(reg))(x)
    output_layer = Dense(X.shape[1], activation=last_activation, name='UserScorePred', kernel_regularizer=regularizers.l2(reg))(x)
    model = Model(input_layer, output_layer)

    return model

AutoRec = AutoRec(train_zero, 0.0005, 'elu', 'elu')

AutoRec.compile(optimizer = Adam(lr=0.0001), loss=masked_mse, metrics=[masked_rmse_clip])
 
AutoRec.summary()


hist_model = AutoRec.fit(x=train_average, y=train_zero,
                  epochs=5,
                  batch_size=256,
                  verbose = 2, 
                  validation_data=(train_average, validate))

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

Comments

1

You should try to change the shape of your input layer, or to see of their is a probleme in your data. Also, I don't know if it's wanted from you but your model only have input and output layer, maybe you forgot you add your dense layer 'x' in the "AutoRec" function.

Comments

0

can you show us the code of your NN model and the kind of data you are giving to it ? I think that the problem is that you are giving data which is composed of 2 tensor but your model input layer is programed to only receive 1 tensor data.

Comments

0

i was able to fix this error by first defining it outside and use it

data_valid =(train_average, validate)

then

hist_model = Model.fit(x=train_average, y=train_zero,
                  epochs=5,
                  batch_size=256,
                  verbose = 2, 
                  validation_data=data_valid)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.