TypeError: __init__() takes exactly 1 argument (2 given)
这段代码摘自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
新手初出茅庐,请多多指教!
...全文
相关推荐
Python 'takes exactly 1 argument (2 given)' Python error
主要介绍了Python 'takes exactly 1 argument (2 given)' Python error的相关资料,需要的朋友可以参考下
实例讲解Python中函数的调用与定义
主要介绍了Python中函数的调用与定义,是Python入门学习中的基础知识,需要的朋友可以参考下
Passing arguments to Python functions
深入讲解了python函数传参的原理,值得一看
PYTHON学习教程:调用函数代码知识点讲解及练习.docx
PYTHON学习教程:调用函数代码知识点讲解及练习.docx
Python语言基础:函数的调用.pptx
对于已有的函数,可以通过另一个函数调用执行,也可以直接从 Python 命令提示符执行。 例如:调用Python内建函数中的abs函数,可以用来求数字的绝对值。 >>> abs(100) 100 函数abs有一个参数,当调用函数的时候,如果传入的参数数量不对,会报TypeError的错误: >>> abs() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: abs() takes exactly one argument (0 given) 对于Python中的函数,在调用之前可以通过help函数来进行查看。 语法格式:help(被查看函数的函数名) 实例:查看abs函数的相关信息


其他技术讨论专区
