I'm working on a face recognition project in which we are using PCA to reduce feature vector size of an image. The trouble is, during training, I create the PCA object by incorporating all the training images. Now, during testing, I need the PCA object obtained earlier.
I cannot seem to figure out how to write the PCA object to a file, so that I can use it during testing. One alternative is that I write it's eigenvectors to the file. But it would be so much more convenient to write the object itself. Is there a way to do this?
As far as I know, there is no generic way of saving PCA objects to a file. You will need to save eigenvectors, eigenvalues and mean to a file, and then put them into a new PCA after loading. You have to remember to use a format that doesn't lose precision, especially for mean.
Here is some example code:
You may try this.
Here is the source.