Keras 中的错误:传递给 K.function 的参数 'metrics' 无效

error in Keras: Invalid argument 'metrics' passed to K.function

我正在研究一些关于机器学习的问题,想尝试 python 中强大的包 Keras(使用 Theano 后端)。虽然我是 运行 用于数字识别的 MLP 演示 here,但它给出了以下错误消息:

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

我不知道为什么会报错,谁能帮我解决这个问题?提前谢谢你。

你是哪个版本的 Keras 运行?

我更新了(例如,"pip install --upgrade keras"),现在该关键字已被接受。

但是请注意,因为其他几个功能已更改。例如,如果您想在训练后访问层输入和输出,则模型方法函数已更改。

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

此错误意味着您是 运行 Keras 版本 0(例如 0.3.2)但是 运行 代码是为 Keras 版本 1 编写的。您可以升级到 Keras 1,或删除 metrics=['accuracy'] 从函数调用到 model.compile().