Home > Net >  I am having an error with my Perceptron Model
I am having an error with my Perceptron Model

Time:11-15

I am building a perceptron model with 1 input and 1 output but I am encountering the following error:

"ValueError: Found unexpected keys that do not correspond to any Model output: dict_keys(['output_1']). Expected: ['output1']"

I have built the model as follows:

#Inputs
input1= keras.Input(shape=(1,))

flatten=keras.layers.Flatten()
    
#Hidden Layer
dense1= keras.layers.Dense(128, activation='sigmoid')


#Outputs

dense2= keras.layers.Dense(1, activation='sigmoid', name= "output1")

x1= input1

x1=dense1(x1)

output1= dense2(x1)


model= keras.Model(input1, output1, name="2_Layer_Perceptron_Model")

loss1=keras.losses.MeanSquaredError()
#loss2=keras.losses.MeanSquaredError()
optim= keras.optimizers.Adam(learning_rate=0.001)
metrics=["accuracy"]

losses= {
    "output_1": loss1,
    #"output_2": loss2,
}

model.compile(loss=losses, optimizer= optim, metrics= metrics)

I have been trying to fit the model with the following command:

model.fit(x_train, y_train, epochs=5,  batch_size= 64, verbose=2)

But I get the error mentioned above.

My Model is a Perceptron feedforward neural network with 1 hidden layer and 1 output layer with the model summary shown by following the link below:

Model Summary

My dataset is split as follows:

x1=df['x1'].values

y1=df['y1'].values

x_train,x_test,y_train,y_test = train_test_split(x1,y1,test_size = 0.2, random_state = 0)

Any and all feedback is appreciated. Thank you

CodePudding user response:

There is no need to create a dictionary of losses.
Use this line:

model.compile(loss=loss1, optimizer= optim, metrics= metrics)
  • Related