【问题标题】:C# HMM Gesture Recognition usng KinectC# HMM 手势识别使用 Kinect
【发布时间】:2013-03-13 11:03:08
【问题描述】:

我正在研究一种使用 Kinect 传感器进行手势识别的解决方案。 现在我正在使用 Accord .NET 来训练 HMM。 我有一个保存手势的数据集。该数据集有 11 个手势,每个手势有 32 帧,保存了 18 个点。

所以我有一个 (double [12] [32,18]) 输入数据集和一个 (int[12]) 输出数据集,但是当我这样做时: double error = teacher.Run(inputSequences, output),它给了我这个:“指定的参数超出了有效值的范围。”

有谁知道如何解决这个问题?在hmm老师上使用之前应该先处理数据集还是数据集可以这样?

【问题讨论】:

    标签: c# kinect hidden-markov-models accord.net


    【解决方案1】:

    我过去使用过 Accord.NET,它确实是 HMM 引擎的最佳实现之一。然而,当我训练我的 HMM 时,我将 HMM 参数(即 PI、A 和 B)传递给 Baum Welch 老师,输入数据集使用有组织的 Excel 表提供。 (类似于 Accord 的作者本人在他的项目中使用的)。我不知何故觉得,由于您将数据集存储为多维数组并直接提供给老师,因此无法正确处理。也许您可以一次提供一个手势记录,或者完全更改数据集的存储结构。如果您还没有阅读 Accord 的整个示例,我建议您阅读整个示例,因为它对我来说效果很好。

    【讨论】:

      【解决方案2】:

      问题可能是教学算法期望训练序列的格式为 double[12][32][18],而不是 double[12][32,18]。训练数据应该是多变量点序列的集合。还需要注意的是,如果您有 11 种可能的手势类别,int[12] 数组中给出的整数标签应该只包含 0 到 10 之间的值。

      因此,如果您有 12 个手势样本,每个包含 32 帧,并且每帧是 18 个点的向量,您应该为教师提供包含观察结果的 double[12][32][18] 数组和包含预期的 int[12] 数组类标签。

      HiddenMarkovClassifierLearning documentation page 中提取的以下示例应该有助于了解如何组织向量!

      // 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 };
      

      在上面的代码中,我们为 2 个观察序列设置了问题,其中每个序列包含 5 个观察,并且每个观察由 2 个值组成。如您所见,这是一个 double[2][5][2] 数组。类标签数组由 int[2] 给出,仅包含从 0 到 1 的值。

      现在,为了使示例更完整,我们可以使用以下代码继续创建和训练模型:

      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);
      

      现在我们可以测试模型,断言输出类标签确实符合我们的预期:

      // 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);
      

      【讨论】:

        猜你喜欢
        • 2013-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-13
        • 2011-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多