Kadir Erdem Demir
Kadir Erdem Demir

Reputation: 3595

Calling OpenCV trainEM function multiple times with different samples

For speaker identification I need to use GMM algorithm and I chose OpenCV library for implementation.

I have a vector member variable of ml::EM for each speaker:

std::vector< cv::Ptr<cv::ml::EM> > gMFCCVec;

And I have a method which simply calls trainEM for given speaker.

void train(size_t speakerID, cv::Mat& samples)
{
    gMFCCVec[speakerID]->trainEM(samples);
} 

My questions can I call trainEM method with different samples. I have cv::Mat data1, and cv::Mat data2. If I call like:

 trainEM(data1);
 trainEM(data2);

will ml::EM be trained with both data1 and data2. Or the training result of the last one will override the first one (in this case ml::EM will be only trained with data2)?

Upvotes: 1

Views: 414

Answers (1)

Miki
Miki

Reputation: 41765

Training result of the last one will override the first one.


You can see in the implementation that trainEM calls setTrainData:

bool trainEM(InputArray samples,
           OutputArray logLikelihoods,
           OutputArray labels,
           OutputArray probs)
{
    Mat samplesMat = samples.getMat();
    setTrainData(START_AUTO_STEP, samplesMat, 0, 0, 0, 0);
    return doTrain(START_AUTO_STEP, logLikelihoods, labels, probs);
}

and that setTrainData calls clear():

void setTrainData(int startStep, const Mat& samples,
                  const Mat* probs0,
                  const Mat* means0,
                  const std::vector<Mat>* covs0,
                  const Mat* weights0)
{
    clear();
    ...

and that clear just clears the previous trained data:

void clear()
{
    trainSamples.release();
    ...

Upvotes: 1

Related Questions