动态手势的隐马尔可夫模型训练? [英] Hidden Markov Model Training for Dynamic Gestures?

查看:289
本文介绍了动态手势的隐马尔可夫模型训练?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多与隐马尔可夫模型有关的材料,并且我还阅读了与该主题有关的所有问题和答案.我知道它是如何工作的以及如何进行训练,但是当尝试以简单的动态手势进行训练时,我无法解决以下问题.

I know there is a lot of material related to hidden markov model and I have also read all the questions and answers related to this topic. I understand how it works and how it can be trained, however I am not able to solve the following problem I am having when trying to train it for a simple dynamic gesture.

我正在为OpenCV使用 HMM实施 我调查了以前问过的问题,并在此处一个>.这确实帮助我理解和使用了马尔可夫模型.

I am using HMM implementation for OpenCV I have looked into previously asked questions and answer here. Which has really helped me in understanding and using markov models.

我总共有两个动态手势,它们都是对称的(向左滑动和向右滑动) 共有5个观察值,其中4个是手势的不同阶段,第5个是当这些状态都不发生时的观察值.

I have total of two dynamic gestures, which are both symmetric (swipe left and swipe right) There are total of 5 observations in which 4 are the different stages in the gesture and 5th one is an observation when non of these stages are occuring.

向左轻扫手势包含以下观察结果:1-> 2-> 3-> 4(应触发向左轻扫状态) 同样,向右滑动手势包括以下观察结果:4-> 3-> 2-> 1

Swipe left gesture consists of the following observation: 1->2->3->4 (which should trigger a swipe left state) Likewise Swipe Right gesture consists of the following observation: 4->3->2->1

我有25个序列.我将对每个序列进行20个观察,以使用Baum-Welch算法训练隐马尔可夫模型.

I have 25 sequences. I am taking 20 observations for each of the sequence, which are used to train hidden markov model using Baum-Welch algorithm.

以下是输入序列:

1 0 1 1 0 2 2 2 2 0 0 2 3 3 3 0 0 4 4 4 
4 4 4 4 4 0 3 3 3 3 3 0 0 1 0 0 1 1 0 1 
4 4 4 4 4 4 0 3 3 3 3 3 0 0 1 0 0 1 1 0 
4 4 4 4 4 4 4 0 3 3 3 3 3 0 0 1 0 0 1 1 
1 1 1 1 0 2 2 2 0 1 0 3 3 0 0 0 4 4 4 4 
1 1 1 1 1 0 2 2 2 0 1 0 3 3 0 0 0 4 4 4 
0 1 1 1 1 1 0 2 2 2 0 1 0 3 3 0 0 0 4 4 
0 0 1 1 1 1 1 0 2 2 2 0 1 0 3 3 0 0 0 4 
4 4 0 0 3 0 3 3 3 3 0 0 0 0 0 1 1 1 1 1 
4 4 4 0 0 3 0 3 3 3 3 0 0 0 0 0 1 1 1 1 
4 4 4 4 0 0 3 0 3 3 3 3 0 0 0 0 0 1 1 1 
1 1 1 1 0 0 2 2 0 3 2 3 3 3 0 0 4 4 4 4 
1 1 1 1 1 0 0 2 2 0 3 2 3 3 3 0 0 4 4 4 
1 1 1 1 1 1 0 0 2 2 0 3 2 3 3 3 0 0 4 4 
1 3 4 4 4 0 3 0 0 0 0 0 3 2 0 0 1 1 1 1 

按此顺序,您可以看到向左滑动和向右滑动手势的模式.

In this sequence you can see pattern for Swipe left and Swipe right gestures.

要训练隐藏的markov模型,请使用以下值对其进行初始化,然后调用train函数以获取输出:

To train the hidden markov model I am initilizing it with the following values and then calling the train function to get the output:

TRANS:
0.7 0.15 0.15
0.3 0.4 0.3
0.3 0.4 0.3

EMIS:
0.3 0.1 0.1 0.1 0.1
0.2 0.1 0.2 0.2 0.3
0.2 0.3 0.2 0.2 0.1

INIT:
0.6 0.2 0.2

训练后的输出为:

TRANS:
0.81611 0.0847926 0.0990979
0.398458 0.346433 0.255109
0.371391 0.35587 0.272739

EMIS:
0.534127 0.125568 0.0824495 0.200169 0.0576869
0.294653 0.0250053 0.0500311 0.200616 0.429694
0.238808 0.075001 0.0500019 0.130455 0.505733

INIT:
0.443984 0.391323 0.164693

在我的识别程序中使用此模型,但没有得到结果. 我希望系统保持空状态,除非检测到手势之一. 在过渡和发射"矩阵中,我给出了这两个手势的猜测值.

Using this model in my recognition program, I am not getting results. I want the system to remain in a NULL STATE unless one of the gesture is detected. In the Transition and Emission matrix I gave my guess values for both these gesture.

您认为我可能做错了什么?有指针或帮助吗?

What do you think I might be doing wrong? Any pointers or help?

最后这是我用来执行此操作的代码(如果有人想看看)

Lastly here is the code I am using for doing this (if anyone wants to have a look)

double TRGUESSdata[] = {0.7, 0.15, 0.15,
                            0.3, 0.4, 0.3,
                            0.3, 0.4, 0.3};
    cv::Mat TRGUESS = cv::Mat(3,3,CV_64F,TRGUESSdata).clone();
    double EMITGUESSdata[] = {0.3, 0.1, 0.1, 0.1, 0.1,
                              0.2, 0.1, 0.2, 0.2, 0.3,
                              0.2, 0.3, 0.2, 0.2, 0.1};
    cv::Mat EMITGUESS = cv::Mat(3,5,CV_64F,EMITGUESSdata).clone();
    double INITGUESSdata[] = {0.6 , 0.2 , 0.2};
    cv::Mat INITGUESS = cv::Mat(1,3,CV_64F,INITGUESSdata).clone();
    std::cout << seq.rows << " "  << seq.cols << std::endl;
    int a = 0;
    std::ifstream fin;
    fin.open("observations.txt");

    for(int y =0; y < seq.rows; y++)
    {
        for(int x = 0; x<seq.cols ; x++)
        {

            fin >> a;
            seq.at<signed int>(y,x) = (signed int)a;
            std::cout << a;
        }
        std::cout << std::endl;
    }

     hmm.printModel(TRGUESS,EMITGUESS,INITGUESS);
    hmm.train(seq,1000,TRGUESS,EMITGUESS,INITGUESS);
    hmm.printModel(TRGUESS,EMITGUESS,INITGUESS);

这里的鳍用于从其他代码中读取我的观察结果.

Here fin is used to read the observation I have from my other code.

推荐答案

0在您的模型中是什么意思?在您的数据中,这两个状态似乎都没有直接转换,它始终会回到状态0.请尝试在数据中执行类似以下操作以获取状态转换序列.

What does the 0 mean in your model ? It seems to me in your data there are no direct transitions for both states, it always goes back to the state 0. Try something like the following in your data for a state transition sequence.

  • 1 1 1 1 2 2 2 3 3 3 3 4 4 4 4 4
  • 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 0 0 0 0 1 1 2 2 3 3 4 4 0 0 0 0 0
  • 4 4 3 3 2 2 1 1 0 0 0 0 0 0 0 0 0
  • 4 4 4 3 3 3 2 2 2 2 2 1 1 1 1 1 1 1

一般规则:

在拥有Matlab/octave的概念证明后,我建议仅在 之后使用openCV.这有两个原因.首先,您确切地知道要做什么以及它是如何工作的,不要浪费时间用低级"语言(与matlab相比)来实现和调试理论.在openCV中调试算法确实很耗时.

I would recommend to work with openCV only after you have a proof of concept in Matlab/octave. This has two reasons. First of all you know exactly what you want to do and how it works, and don't waste your time implementing and debugging your theory in a 'low' level language (compared to matlab). Debugging algorithms in openCV is really time-consuming.

第二,在您知道自己的东西按预期工作之后,如果您实现它并遇到bug(openCV或C ++,python),您就会知道这不是您的理论,不是您的实现,而是框架.我经历过两次的经历,即雇用计算机科学家直接从一篇论文中实现(被告知不这样做),花费了剩余时间的80%来调试算法,但没有成功,只是发现:他们没有真正了解了openCV的理论或某些子模块有一个小错误,导致其结果退化.

Secondly after you know your stuff works as expected, if you implement it and hit a bug (of openCV or C++, python) you know it's not your theory, not your implementation, it's the framework. It happened to me already two times that employed computer scientists implemented directly from a paper (after being told not to do so), spending 80% of the remaining time to debug the algorithm without ANY success only to find out that: they didn't really get the theory or some submodule of openCV had a slight bug which degenerated their results.

您提到的链接在matlab中使用了HMM工具箱.尝试在那里实现并理解您的问题,这确实值得花时间.建立工作模型后,不仅可以验证每个步骤的正确性,还可以在openCV代码中使用迭代矩阵.

The link you've mentioned uses a HMM toolbox in matlab. Try to implement and understand your problem there, it's really worth spending the time. Not only you can verify each step for correctness, you can use the itermediate matrices with your openCV code after you have a working model.

这篇关于动态手势的隐马尔可夫模型训练?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆