【问题标题】:ValueError: Invalid argument 'metric' passed to K.function even with newest Keras/TheanoValueError:即使使用最新的 Keras/Theano,也将无效的参数“度量”传递给 K.function
【发布时间】:2016-07-09 22:21:50
【问题描述】:

当我在 Anaconda / Python2.7 / Keras / Theano 中运行以下非常简单的神经网络时:

import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Activation

# import csv
csv = 'https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv'
iris = np.genfromtxt(csv, delimiter = ',', dtype = None)

# Munge data
iris = np.delete(iris, 0, 0)  # delete header row
iris[iris[:,4] == 'setosa', 4] = 1
iris[(iris[:,4] == 'versicolor') | (iris[:,4] == 'virginica'), 4] = 0
iris = iris.astype(float)

# split into data and label classes
data = iris[:,0:4]
labels = iris[:,4]
labels = np.array([labels])
labels = labels.T
labels = labels.astype(int)

# develop NN
model = Sequential()
model.add(Dense(1, input_dim = 4))
model.add(Activation('softmax'))
model.compile(optimizer = 'rmsprop', loss = 'binary_crossentropy', metric = ['accuracy'])

# fit NN
model.fit(data, labels, nb_epoch = 5, batch_size = 50)

我收到以下错误:

  File "C:\Users\bAXTER\Anaconda\lib\site-packages\keras\backend\theano_backend.py", line 539, in function
    raise ValueError(msg)

ValueError: Invalid argument 'metric' passed to K.function

我查看了这个post,但我已经在 Anaconda (Python 2.7) 上使用 Keras 1.0.5 和 Theano 0.9.0 并安装了所有相关软件包。此外,帖子中提到我可以“从对model.compile()的函数调用中删除metrics=['accuracy']”。但我在“theano_backend.py”中找不到这些术语。我无法评论该用户的回答,因为我没有足够的声誉。

关于为什么 keras 会导致此错误的任何想法?我知道这是一个较少探索的 Python 领域,因此我们将不胜感激。

【问题讨论】:

    标签: python neural-network anaconda theano keras


    【解决方案1】:

    非常尴尬。我在model.compile 命令中拼写为metric 而不是metrics

    【讨论】:

    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多