当我使用 knn 进行识别并运行以下功能时:
def predict(X_img_path, knn_clf=None, model_path=None, distance_threshold=0.49):
if not os.path.isfile(X_img_path) or os.path.splitext(X_img_path)[1][1:] not in
ALLOWED_EXTENSIONS:
raise Exception("Invalid image path: {}".format(X_img_path))
if knn_clf is None and model_path is None:
raise Exception("Must supply knn classifier either thourgh knn_clf or model_path")
if knn_clf is None:
with open(model_path, 'rb') as f:
knn_clf = pickle.load(f)
X_img = face_recognition.load_image_file(X_img_path)
X_face_locations = face_recognition.face_locations(X_img)
if len(X_face_locations) == 0:
return []
faces_encodings = face_recognition.face_encodings(X_img,
known_face_locations=X_face_locations)
closest_distances = knn_clf.kneighbors(faces_encodings, n_neighbors=4)
我收到了这个错误:
Traceback (most recent call last):
File "Recognition.py", line 225, in <module>
predictions = predict(full_file_path, model_path=
"/home/abc/FS/trained_knn_model.clf")
File "Recognition.py", line 75, in predict
closest_distances = knn_clf.kneighbors(faces_encodings, n_neighbors=1)
File "/usr/local/lib/python3.6/dist-packages/sklearn/neighbors/base.py", line 402, in
kneighbors
X = check_array(X, accept_sparse='csr')
File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 542, in
check_array
allow_nan=force_all_finite == 'allow-nan')
File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py", line 56, in
_assert_all_finite
raise ValueError(msg_err.format(type_err, X.dtype))
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
当我在我的 cpu 中运行相同的代码时,它工作正常,但是当我在 jetson nano 中运行时,它显示上述错误。
我的jetson nano配置是
喷气背包 4.2.1 r32.2
Ubuntu 18.04
蟒蛇 3.6.8