我正在研究一种使用Kinect传感器进行手势识别的解决方案。现在我正在使用Accord .NET来训练HMM。我有一个保存了手势的数据集。这个数据集有11个手势,每个手势都有32帧,保存了18个点。
因此,我有一个(双12)输入数据集和一个(int12)输出数据集,但是当我这样做时: double error = teacher.Run(inputSequences,output),它会告诉我:“指定的参数超出了有效值的范围。”
有人知道如何解决这个问题吗?在hmm老师上使用数据集之前应该先处理它,或者数据集是这样的吗?
发布于 2013-04-23 13:51:37
我过去用过Accord.NET,它确实是HMM引擎最好的实现之一。然而,当我训练我的HMM时,我将HMM参数(即PI、A和B)传递给Baum Welch老师,并使用组织好的excel表提供输入数据集。(类似于Accord的作者本人在他的项目中使用的内容)。不知何故,我觉得既然你将数据集存储为多维数组并直接提供给老师,它就无法正确地处理它。也许你可以一次提供一个手势记录,或者完全改变你的数据集的存储结构。如果你还没有,我建议你看一下整个Accord的例子,因为它对我来说工作得很好。
发布于 2014-01-06 19:36:17
问题可能是,教学算法希望训练序列的形式是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个值组成。如您所见,这是一个double22数组。类标签数组由int2提供,只包含从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);https://stackoverflow.com/questions/15383454
复制相似问题