Save trained Random Forest Classifier OpenCV 2.4.13 Python

asked 2017-11-04 05:55:29 -0600

chimes27 gravatar image

updated 2017-11-04 06:05:45 -0600

I am trying to train a Random Forest classifier using OpenCV(2.4.13) and Python(2.7) and save it the result as a XML file. However, the Windows displays "Python.exe has stopped working" error when running my code. Here is a sample my code:

self.params = dict(max_depth=100,
                           min_sample_count=1,
                           use_surrogates=False,
                           max_categories=5,
                           calc_var_importance=False,
                           nactive_vars=0,
                           max_num_of_tree_in_the_forest=100,
                           term_crit=(cv2.TERM_CRITERIA_MAX_ITER,100,1))

features = np.array(features, dtype=np.float32)
        self.model = cv2.RTrees()
        self.model.train(features, cv2.CV_ROW_SAMPLE, label, params=self.params)
        self.model.save('trees.xml')

The error occurs when I added the self.model.save('trees.xml') line but the code works when removed. The model.save also works with other models such as SVM but not in Random Trees. Any idea what's going on and how to solve this problem?

PS. I am running on Windows 7 64-bit Platform

edit retag flag offensive close merge delete