0

When i used knn for recognition and running following function:

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)   

I got this error:

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').

When the same code i m running in my cpu it working fine but when i m running in jetson nano it show above error.

My jetson nano configuration is

Jetpack 4.2.1 r32.2

Ubuntu 18.04

python 3.6.8

safe pro
  • 1
  • 1
  • https://stackoverflow.com/questions/31323499/sklearn-error-valueerror-input-contains-nan-infinity-or-a-value-too-large-for – PV8 Nov 14 '19 at 13:42
  • when i m sending the image to prediction module.In sklearn/utils/validation.py. sometime i got data sometime nan value. where my program breaks. how to fix this. But i m not getting this why this happening in jetson nano and the same code is working fine in another system with same package versions. – safe pro Nov 15 '19 at 07:01

0 Answers0