error in Keras: Invalid argument 'metrics'

2019-04-13 12:12发布

问题:

I am working on some problems about machine learning and want to try the powerful package Keras(using Theano backend) in python. While I am running a demo of MLP for digit recognition here, it gives the follow error message:

Traceback (most recent call last):
File "mlp.py", line 52, in <module>
metrics=['accuracy'])
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 564, in compile
updates=updates, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/theano_backend.py", line 459, in function
raise ValueError(msg)
ValueError: Invalid argument 'metrics' passed to K.function

I don't know why it gave the error message, can anyone help me to fix the bug? Thank you in advance.

回答1:

This error means that you are running Keras version 0 (e.g. 0.3.2) but running code that was written for Keras version 1. You can upgrade to Keras 1, or remove metrics=['accuracy'] from the function call to model.compile().



回答2:

Which version of Keras are you running?

I updated (e.g., "pip install --upgrade keras"), and that keyword is now accepted.

Take care, however, because several other functions have changed. For example, if you would like to access layer input and output after training, the model method functions have changed.

see http://keras.io/layers/about-keras-layers/