我试图制作一个集群管道,但出现以下错误,这表明这里存在一些维度问题:
Traceback (most recent call last):
File "Driver.py", line 57, in <module>
labelIDs = faceClusterUtility.Cluster()
File "/Users/aryansharma/Desktop/FaceRecognitionPipeline_GeeksForGeeks/FaceClusteringLibrary.py", line 241, in Cluster
clt.fit(encodings)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/cluster/_dbscan.py", line 346, in fit
X = self._validate_data(X, accept_sparse="csr")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/base.py", line 566, in _validate_data
X = check_array(X, **check_params)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/utils/validation.py", line 773, in check_array
"if it contains a single sample.".format(array)
ValueError: Expected 2D array, got 1D array instead:
array=[].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
0it [00:02, ?it/s]
这是显示错误的代码部分。下面的函数通过加载嵌入来定义聚类,然后执行聚类。它应该输出集群标签。
def Cluster(self):
InputEncodingFile = self.EncodingFilePath
if not (os.path.isfile(InputEncodingFile) and os.access(InputEncodingFile, os.R_OK)):
print('The input encoding file, ' +
str(InputEncodingFile) + ' does not exists or unreadable')
exit()
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_