Ask Your Question

KNearest save problem

asked 2012-08-08 07:15:58 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I realized that and knn.load() function is not implemented yet. I googled so much about that couldn't find any solution for that.

If there is a solution i will be happy to know that. Any help would be appreciated.

edit retag flag offensive close merge delete


Can you clarify what and knn.load() are supposed to do? Is the idea to save and load a trained model that would be produced by CvKNearest::train()?

martyychang gravatar imagemartyychang ( 2016-03-23 19:12:49 -0500 )edit

2 answers

Sort by » oldest newest most voted

answered 2016-12-20 11:44:27 -0500

updated 2016-12-20 11:45:35 -0500

kNN does not save a model because there is no model to save. The model is the complete data. It classifies new samples by going through the raw data and verifying the k closest samples and using the classes as votes.

I agree that it shouldn't provide the method if it is redundant.

edit flag offensive delete link more

answered 2018-06-10 13:13:22 -0500

I use:'knn.yml')

to save the model


fs = cv2.FileStorage('knn.yml', cv2.FILE_STORAGE_READ)
knn_yml = fs.getNode('opencv_ml_knn')

knn_format    = knn_yml.getNode('format').real()
is_classifier = knn_yml.getNode('is_classifier').real()
default_k     = knn_yml.getNode('default_k').real()
samples       = knn_yml.getNode('samples').mat()
responses     = knn_yml.getNode('responses').mat()

to recover it. I hope be of some help

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-08-08 07:15:58 -0500

Seen: 583 times

Last updated: Jun 10 '18