属性错误:“builtin_function_or_method”对象没有属性“index”[已关闭]

问题描述 投票:0回答:1

我正在努力训练和生成混淆矩阵,但我不断收到此错误,我已经仔细检查了数据集可以帮助我

错误:

def load_face_dataset(inputPath, net, minConfidence=0.5,
    minSamples=15):
    # grab the paths to all images in our input directory, extract
    # the name of the person (i.e., class label) from the directory
    # structure, and count the number of example images we have per
    # face
    imagePaths = list(paths.list_images(inputPath))
    names = [p.split(os.path.sep)[-2] for p in imagePaths]
    (names, counts) = np.unique(names, return_counts=True)
    names = names.tolist
    # initialize lists to store our extracted faces and associated
    # labels
    faces = []
    labels = []
    # loop for the image paths
    for imagePath in imagePaths:
        # load the image from disk and extract the name of the person
        # from the subdirectory structure
        image = cv2.imread(imagePath)
        name = imagePath.split(os.path.sep)[-2]
        # only process images that have a sufficient number of
        # examples belonging to the class
        if counts[names.index(name)] < minSamples:
            continue
        # perform face detection
        boxes = detect_faces(net, image, minConfidence)
        # loop over the bounding boxes
        for (startX, startY, endX, endY) in boxes:
            try:
                # extract the face ROI, resize it, and convert it to
                # grayscale
                faceROI = image[startY:endY, startX:endX]
                faceROI = cv2.resize(faceROI, (47, 62))
                faceROI = cv2.cvtColor(faceROI, cv2.COLOR_BGR2GRAY)
                # update our faces and labels lists
                faces.append(faceROI)
                labels.append(name)
            except:
                continue
    # convert our faces and labels lists to NumPy arrays
    faces = np.array(faces)
    labels = np.array(labels)
    # return a 2-tuple of the faces and labels
    return (faces, labels)

我尝试从头开始再次分析和编码,但我仍然收到此错误

python python-3.x
1个回答
1
投票

你正在做:

names = names.tolist
#output
<function ndarray.tolist>

当你对函数上的names.index执行操作时,你会得到:

AttributeError: 'builtin_function_or_method' object has no attribute 'index'

你必须做:

names = names.tolist()
© www.soinside.com 2019 - 2024. All rights reserved.