简体   繁体   English

使用Kinect进行C#HMM手势识别

[英]C# HMM Gesture Recognition usng Kinect

I'm working on a solution to do gesture recognition using the Kinect sensor. 我正在研究使用Kinect传感器进行手势识别的解决方案。 Now I'm using Accord .NET to train the HMM. 现在,我正在使用Accord .NET训练HMM。 I have a dataset with saved gestures. 我有一个保存了手势的数据集。 This dataset has 11 gestures and each one has 32 frames with 18 points saved. 该数据集有11个手势,每个手势有32个帧,保存了18个点。

So I have a (double [12] [32,18]) input dataset and a (int[12]) output dataset, but when i do: double error = teacher.Run(inputSequences, output), it gives me this : "Specified argument was out of the range of valid values." 所以我有一个(double [12] [32,18])输入数据集和一个(int [12])输出数据集,但是当我这样做时:double error = Teacher.Run(inputSequences,output),它给了我这个: “指定的参数超出有效值范围。”

Does anyone knows how to solve this? 有谁知道如何解决这个问题? Should treat the dataset before using it o on the hmm teacher or the dataset is ok like this? 是否应该在hmm老师上使用数据集之前对其进行处理,否则数据集可以这样吗?

I have used Accord.NET in the past and its really one of the best implementations for a HMM engine. 我过去曾经使用过Accord.NET,它实际上是HMM引擎的最佳实现之一。 However, when I trained my HMM, I passed the HMM parameters (namely PI, A and B) to the Baum Welch Teacher with the input data set supplied using an organized excel sheet. 但是,当我训练HMM时,我将HMM参数(即PI,A和B)传递给Baum Welch老师,并使用组织好的excel表提供了输入数据集。 (similar to what Accord's author himself has used in his project). (类似于Accord的作者本人在其项目中使用的内容)。 I somehow feel that since you are storing your data set as a multi-dimensional array and directly supplying it to the teacher, its unable to process it properly. 我不知何故感觉到,由于您将数据集存储为多维数组并直接将其提供给教师,因此它无法正确处理它。 Maybe you could supply one gesture record at a time or change the storage structure of your data set altogether. 也许您可以一次提供一个手势记录,或者完全更改数据集的存储结构。 I advice going through the entire example of Accord if you haven't already because it worked just fine for me. 如果您还没有使用Accord的整个示例,我建议您进行遍历,因为它对我来说很好用。

The problem might have been that the teaching algorithm expects the training sequences to be in the form double[12][32][18] , rather than double[12][32,18] . 问题可能在于教学算法期望训练序列采用double[12][32][18] ,而不是double[12][32,18] The training data should be a collection of sequences of multivariate points. 训练数据应该是多变量点序列的集合。 It should also be necessary to note that, if you have 11 possible classes of gestures, the integer labels given in the int[12] array should be comprised of values between 0 and 10 only. 还需要注意的是,如果您有11种可能的手势类,则int[12]数组中给出的整数标签应仅由0到10之间的值组成。

Thus if you have 12 gesture samples, each containing 32 frames, and each frame is a vector of 18 points, you should be feeding the teacher with a double[12][32][18] array containing the observations and a int[12] array containing the expected class labels. 因此,如果您有12个手势样本,每个样本包含32个帧,并且每个帧是18个点的向量,则应该为教师提供一个double[12][32][18]数组,其中包含观察值和一个int[12]数组,其中包含所需的类标签。

The example below, extracted from the HiddenMarkovClassifierLearning documentation page should help to give an idea how the vectors should be organized! 下面的示例摘自HiddenMarkovClassifierLearning文档页面 ,该示例应该有助于给出向量的组织方式!

// Create a Continuous density Hidden Markov Model Sequence Classifier 
// to detect a multivariate sequence and the same sequence backwards. 

double[][][] sequences = new double[][][]
{
    new double[][] 
    { 
        // This is the first  sequence with label = 0 
        new double[] { 0, 1 },
        new double[] { 1, 2 },
        new double[] { 2, 3 },
        new double[] { 3, 4 },
        new double[] { 4, 5 },
    }, 

    new double[][]
    {
            // This is the second sequence with label = 1 
        new double[] { 4,  3 },
        new double[] { 3,  2 },
        new double[] { 2,  1 },
        new double[] { 1,  0 },
        new double[] { 0, -1 },
    }
};

// Labels for the sequences 
int[] labels = { 0, 1 };

In the above code, we have set the problem for 2 sequences of observations, where each sequence containing 5 observations, and in which each observations is comprised of 2 values. 在上面的代码中,我们为2个观测序列设置了问题,其中每个序列包含5个观测,并且每个观测由2个值组成。 As you can see, this is a double[2][5][2] array. 如您所见,这是一个double [2] [5] [2]数组。 The array of class labels is given by a int[2], containing only values ranging from 0 to 1. 类标签数组由int [2]给出,只包含0到1范围内的值。

Now, to make the example more complete, we can continue creating and training the model using the following code: 现在,为了使示例更完整,我们可以继续使用以下代码创建和训练模型:

var initialDensity = new MultivariateNormalDistribution(2);

// Creates a sequence classifier containing 2 hidden Markov Models with 2 states 
// and an underlying multivariate mixture of Normal distributions as density. 
var classifier = new HiddenMarkovClassifier<MultivariateNormalDistribution>(
    classes: 2, topology: new Forward(2), initial: initialDensity);

// Configure the learning algorithms to train the sequence classifier 
var teacher = new HiddenMarkovClassifierLearning<MultivariateNormalDistribution>(
    classifier,

    // Train each model until the log-likelihood changes less than 0.0001
    modelIndex => new BaumWelchLearning<MultivariateNormalDistribution>(
        classifier.Models[modelIndex])
    {
        Tolerance = 0.0001,
        Iterations = 0,

        FittingOptions = new NormalOptions()
        {
            Diagonal = true,      // only diagonal covariance matrices
            Regularization = 1e-5 // avoid non-positive definite errors
        }
    }
);

// Train the sequence classifier using the algorithm 
double logLikelihood = teacher.Run(sequences, labels);

And now we can test the model, asserting that the output class label indeed matches what we are expecting: 现在我们可以测试模型了,断言输出类标签确实符合我们的期望:

// Calculate the probability that the given 
//  sequences originated from the model 
double likelihood, likelihood2;

// Try to classify the 1st sequence (output should be 0) 
int c1 = classifier.Compute(sequences[0], out likelihood);

// Try to classify the 2nd sequence (output should be 1) 
int c2 = classifier.Compute(sequences[1], out likelihood2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM