开发者社区> 问答> 正文

TypeError: __init__() takes exactly 1 ar?报错

这段代码摘自Philipp博客(http://bytefish.de/blog/fisherfaces/;https://github.com/bytefish/facerec)

如下为 fisherfaces_example.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) Philipp Wagner. All rights reserved.
# Licensed under the BSD license. See LICENSE file in the project root for full license information.

import sys
import os
# append facerec to module search path
sys.path.append("../..")
# import facerec stuff
from facerec.dataset import NumericDataSet
from facerec.feature import Fisherfaces
from facerec.distance import EuclideanDistance, CosineDistance
from facerec.classifier import NearestNeighbor
from facerec.classifier import SVM
from facerec.model import PredictableModel
from facerec.validation import KFoldCrossValidation
from facerec.visual import subplot
from facerec.util import minmax_normalize
# import numpy
import numpy as np
# import matplotlib colormaps
import matplotlib.cm as cm
# import for logging
import logging
import sys
# set up a handler for logging
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# add handler to facerec modules
logger = logging.getLogger("facerec")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
# load a dataset (e.g. AT&T Facedatabase)
dataSet = NumericDataSet("C:\Users\WT\Desktop\jpg")#"/home/philipp/facerec/data/yalefaces_recognition"
#os.path.join('C:\Users\WT\Desktop\jpg\s1', '1.pgm')
# define Fisherfaces as feature extraction method
feature = Fisherfaces()
# define a 1-NN classifier with Euclidean Distance
classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=1)
# define the model as the combination
model = PredictableModel(feature=feature, classifier=classifier)
# show fisherfaces
model.compute(dataSet.data, dataSet.labels)
# turn the first (at most) 16 eigenvectors into grayscale
# images (note: eigenvectors are stored by column!)
E = []
for i in xrange(min(model.feature.eigenvectors.shape[1], 16)):
    e = model.feature.eigenvectors[:, i].reshape(dataSet.data[0].shape)
    E.append(minmax_normalize(e, 0, 255, dtype=np.uint8))
# plot them and store the plot to "python_fisherfaces_fisherfaces.pdf"
subplot(title="Fisherfaces", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="fisherfaces.pdf")
# perform a 10-fold cross validation
cv = KFoldCrossValidation(model, k=10)
cv.validate(dataSet.data, dataSet.labels)
cv.print_results()



运行报错:C:\Python\python.exe I:/facerec-master/py/apps/scripts/fisherfaces_example.py
Traceback (most recent call last):
  File "I:/facerec-master/py/apps/scripts/fisherfaces_example.py", line 37, in <module>
    dataSet = NumericDataSet("C:\Users\WT\Desktop\jpg")
TypeError: __init__() takes exactly 1 argument (2 given)


Process finished with exit code 1

新手初出茅庐,请多多指教!

展开
收起
爱吃鱼的程序员 2020-06-09 15:50:04 937 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    NumericDataSet这个类的__init__方法只能接受一个参数,而这第一个参数必定是对象本身,所以初始化这个类的实例的时候就不能再接受更多的参数了。

    也就是说只能这样用dataSet=NumericDataSet()

    回复 @443090479:example过时了,看着facerec的源码研究吧。有了新的错误:File"fisherfaces_example.py",line47,in<module>model.compute(dataSet.data,dataSet.labels)AttributeError:'NumericDataSet'objecthasnoattribute'labels'你好,原作者写的是dataSet=NumericDataSet("/home/philipp/facerec/data/yalefaces_recognition"),所以我觉得这儿可能确实需要给个参数,在无参时此处未报错,但显示:

    https://github.com/bytefish/facerec/commit/a8929296ce4df971329fa5fd51299b703d2da9fa

    看这个提交,更新了接口。

    2020-06-09 15:50:20
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
3D/AR技术在新零售商业场景中的应用 立即下载
从2D到3D ,AR发展中的关键技术 立即下载
从2D到3D,AR发展中 的关键技术 立即下载