I would like to know if there exists any method/function which can be used for saving a trained EM (Expectation Maximization or Gaussian Mixture Model) model defined in OpenCV by using Python?
I have already tried Pickle dump() method but its not working. It shows an error: TypeError: can't pickle EM objects. And also, I have tried other simple method like file opening and writing (in XML format). However, its also not working.
Here is a part of my Python code:
import cv2
import numpy as np
from sklearn import mixture
im = cv2.imread('001.png', False)
PCenter = [2,2]
pyrDown_img = im.copy()
X_train = []
gmm_clf = cv2.EM(12, cv2.EM_COV_MAT_DIAGONAL) # Initialize classifier object
for row in range(PCenter[0], pyrDown_img.shape[0] - PCenter[0]):
for col in range(PCenter[1], pyrDown_img.shape[1] - PCenter[1]):
patch = pyrDown_img[row-PCenter[0]:row+PCenter[0]+1, col-PCenter[1]:col+PCenter[1]+1]
patch = np.asarray(patch) # compute patch as a feature vector
X_train.append(patch.reshape(-1))
X_train = np.asarray(X_train)
gmm_clf.train(X_train) # train GMM classifier
I want to save this gmm_clf into a file, so that I can use it later for a testing purpose.