shanren7/real_time_face_recognition

[sklearn version 0.18.1 - 0.19.0] retrain or use another classifier beside knn_classifier.model?

dragon28 opened this issue · 3 comments

Hello people,

Manage to get the code up and running which got the solution from #1 (comment) @JIEMIN1995

but having some minor issue with scikit-learn version 0.18.1 to 0.19.0

/home/test/.local/lib/python2.7/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-8-48c676bed78e> in <module>()
     49 
     50             #crop = cv2.resize(crop, (96, 96), interpolation=cv2.INTER_CUBIC )
---> 51             crop = cv2.resize(crop, (160, 160), interpolation=cv2.INTER_CUBIC )
     52 
     53             #data=crop.reshape(-1,96,96,3)

error: /home/test/opencv-2.4.13.3/modules/imgproc/src/imgwarp.cpp:1968: error: (-215) ssize.area() > 0 in function resize

I wonder how to do you guys pretrain or export the KNN model from scikit-learn? any resource or direction which you can point? @shanren7 mind point out the direction?

Thanks

Ok, I went to https://zhuanlan.zhihu.com/p/25025596

and got the knn classifier code which was:

from sklearn import metrics  
from sklearn.externals import joblib

X_train, X_test, y_train, y_test = train_test_split(X, train_y, test_size=.3, random_state=42)

# KNN Classifier  
def knn_classifier(train_x, train_y):  
    from sklearn.neighbors import KNeighborsClassifier  
    model = KNeighborsClassifier()  
    model.fit(train_x, train_y)  
    return model  

classifiers = knn_classifier 

model = classifiers(X_train,y_train)  
predict = model.predict(X_test)  

accuracy = metrics.accuracy_score(y_test, predict)  
print ('accuracy: %.2f%%' % (100 * accuracy)  ) 
  
    
#保存模型
joblib.dump(model, 'knn.model')

however, there were several problem such as:

train_test_split function was not define
X was not define
train_y was not define

Thanks

Hi, I have the same issue, @dragon28 ,just uninstall scikit-learn version 0.19.0, then install 0.18.1 to solve this issue