我试图制作一个人脸聚类管道,但我得到了一个错误,即: 追溯(最近一次通话): 文件“Driver.py”,第 57 行,位于 labelIDs = faceClusterUtility.Cluster() 文件“/Users/aryansharma/Desktop/FaceRecognitionPipeline_GeeksForGeeks/FaceClusteringLibrary.py”,第 241 行,在集群中 clt.fit(编码) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/cluster/_dbscan.py”,第 346 行,适合 X = self._validate_data(X, accept_sparse="csr") 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/base.py”,第 566 行,在 _validate_data 中 X = check_array(X, **check_params) 文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/utils/validation.py”,第 773 行,在 check_array “如果它包含一个样本。”.format(array) ValueError:预期的二维数组,得到的是一维数组: 数组=[]。 如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 重塑您的数据,如果它包含单个样本,则使用 array.reshape(1, -1) 。 0it [00:02, ?it/s]
显示错误的代码部分是:
def集群(自身): InputEncodingFile = self.EncodingFilePath 如果不是(os.path.isfile(InputEncodingFile)和 os.access(InputEncodingFile,os.R_OK)): print('输入编码文件,' + str(InputEncodingFile) + '不存在或不可读') 出口()
NumberOfParallelJobs = -1
# load the serialized face encodings + bounding box locations from
# disk, then extract the set of encodings to so we can cluster on
# them
print("[INFO] Loading encodings")
data = pickle.loads(open(InputEncodingFile, "rb").read())
data = np.array(data)
encodings = [d["encoding"] for d in data]
# cluster the embeddings
print("[INFO] Clustering")
clt = DBSCAN(eps=0.5, metric="euclidean", n_jobs=NumberOfParallelJobs)
clt.fit(encodings)
# determine the total number of unique faces found in the dataset
labelIDs = np.unique(clt.labels_)
numUniqueFaces = len(np.where(labelIDs > -1)[0])
print("[INFO] # unique faces: {}".format(numUniqueFaces))
return clt.labels_