Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to load CV2.ml_Knearest pre-trained classifier back into Python memory?

Hello! I encountered with the problem with loading pre-trained 'cv2.ml_KNearest' classifier into Python 3.6. I trained and saved 'cv2.ml_KNearest' classifier to the HDD using the following code:

kNearest = cv2.ml.KNearest_create()
kNearest.train(img_array_train, cv2.ml.ROW_SAMPLE, img_classes_labels)
kNearest.save('KNN_Trained_Model.xml')

but I can't find anywhere the command or approach to get it back from ''KNN_Trained_Model.xml'' file to python memory as "cv2.ml.KNearest" classifier object. I know that fore some reasons method "cv2.ml.KNearest_read()" has not been implemented in python OpenCV libraries for Python 3.x. I would appreciate any help with this.