Ask Your Question
0

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

asked 2019-08-01 05:15:55 -0600

Andrew.K gravatar image

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-08-01 05:53:38 -0600

LBerger gravatar image

updated 2019-08-01 05:54:05 -0600

You must use cv.ml.KNearest_load opencv 4.1.1

edit flag offensive delete link more

Comments

Thank you! I also found this method before, however the most recent version that available in the OpenCV repository is just 4.1.0.25.

Andrew.K gravatar imageAndrew.K ( 2019-08-01 06:19:43 -0600 )edit

sorry I push in april 17 and lastest version april 11 Wait for next release

LBerger gravatar imageLBerger ( 2019-08-01 06:28:13 -0600 )edit
1

Thank you very much! Next release totally suits me.

Andrew.K gravatar imageAndrew.K ( 2019-08-01 07:47:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-08-01 04:53:56 -0600

Seen: 1,352 times

Last updated: Aug 01 '19