这段代码摘自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
新手初出茅庐,请多多指教!
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
看这个提交,更新了接口。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。