6

The following line of code gives me the above error in Keras. model is a Graph model in Keras.

score, acc = model.evaluate({
    'input1': X_test1,
    'input2': X_test2,
    'output':Y_test}, batch_size=450)

but when I change it to the following, it runs fine.

predictions = model.predict({
    'input1': X_test1,
    'input2': X_test2}, batch_size=450)['output']

The Y_test here is a <type 'numpy.ndarray'> of <type 'numpy.ndarray'>. A one-hot encoded vector.

Sample Y_test:

[[1.,0.,0.],[1.,0.,0.],[0.,0.,1.]]

2 Answers 2

10

As you can see here :

https://github.com/fchollet/keras/blob/master/keras/engine/training.py

The evaluate method returns only test loss (or losses). So assigning result of this method to a pair results in error.

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

3 Comments

Thank you, for pointing that out. It seemed to work fine for the Sequential model, but now I am guessing that it returns two metrics.
Actually, it returns the test loss and any metrics requested. Assigning the result to a pair score, acc would have worked had the accuracy metric been requested from the model fitting
This is an quite old answer. Keras changed a lot since this time.
0

Using keras 1.0 I was able to get the score print out but I would receive this error when I tried to get the score and accuracy.

I downgraded my keras to 0.3.3, and ran the exact same code. I was able to get score and accuracy doing this.

Comments

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.