[英]C# HMM Gesture Recognition usng Kinect
我正在研究使用Kinect傳感器進行手勢識別的解決方案。 現在,我正在使用Accord .NET訓練HMM。 我有一個保存了手勢的數據集。 該數據集有11個手勢,每個手勢有32個幀,保存了18個點。
所以我有一個(double [12] [32,18])輸入數據集和一個(int [12])輸出數據集,但是當我這樣做時:double error = Teacher.Run(inputSequences,output),它給了我這個: “指定的參數超出有效值范圍。”
有誰知道如何解決這個問題? 是否應該在hmm老師上使用數據集之前對其進行處理,否則數據集可以這樣嗎?
我過去曾經使用過Accord.NET,它實際上是HMM引擎的最佳實現之一。 但是,當我訓練HMM時,我將HMM參數(即PI,A和B)傳遞給Baum Welch老師,並使用組織好的excel表提供了輸入數據集。 (類似於Accord的作者本人在其項目中使用的內容)。 我不知何故感覺到,由於您將數據集存儲為多維數組並直接將其提供給教師,因此它無法正確處理它。 也許您可以一次提供一個手勢記錄,或者完全更改數據集的存儲結構。 如果您還沒有使用Accord的整個示例,我建議您進行遍歷,因為它對我來說很好用。
問題可能在於教學算法期望訓練序列采用double[12][32][18]
,而不是double[12][32,18]
。 訓練數據應該是多變量點序列的集合。 還需要注意的是,如果您有11種可能的手勢類,則int[12]
數組中給出的整數標簽應僅由0到10之間的值組成。
因此,如果您有12個手勢樣本,每個樣本包含32個幀,並且每個幀是18個點的向量,則應該為教師提供一個double[12][32][18]
數組,其中包含觀察值和一個int[12]
數組,其中包含所需的類標簽。
下面的示例摘自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 };
在上面的代碼中,我們為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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.