我想问你是否可以使用散列技术和SURF算法,我制作了一个程序,通过将测试图像与保存的图像数据集进行匹配来进行人脸识别。
我使用Accord.net并通过这个库的BOW制作了一些功能然后我制作了ID3决策树和KNN,但两种方式的结果都不是很好,我问我是否可以使用散列技术来快速制作更好的结果,或者这是不可行的? 这是BOW的代码
private void button2_Click(object sender, EventArgs e)
{
try
{
var watchFEC = System.Diagnostics.Stopwatch.StartNew();
Accord.Math.Random.Generator.Seed = 0;
bow.ParallelOptions.MaxDegreeOfParallelism = 1;
bow.Learn(DatasetImages);
// After this point, we will be able to translate
// images into double[] feature vectors using
features = bow.Transform(DatasetImages);
watchFEC.Stop();
var elapsedMs = watchFEC.ElapsedMilliseconds;
MessageBox.Show("Feature Extraction and Clastering is done" + '\n' + "Time for Feature Extraction and Clastering for Dataset is: " + elapsedMs.ToString() + " ms");
} catch { MessageBox.Show("Error"); } }
这是学习的代码
private void button3_Click(object sender, EventArgs e)
{
try
{
var watchLearn = System.Diagnostics.Stopwatch.StartNew();
inputs = features.ToInt32();
tree = teacher.Learn(inputs, outputs);
error = new ZeroOneLoss(outputs).Loss(tree.Decide(inputs));
MessageBox.Show("Error rate of learning is : "+error.ToString());
watchLearn.Stop();
var elapsedMs = watchLearn.ElapsedMilliseconds;
MessageBox.Show("Learning is done" + '\n' + "Time for Learning is: " + elapsedMs.ToString() + " ms");
}
catch(Exception ex) { MessageBox.Show("Error"+ex); }
}
以及此测试代码
private void button4_Click_1(object sender, EventArgs e)
{
try
{
var watchTest = System.Diagnostics.Stopwatch.StartNew();
Bitmap[] testimage = new Bitmap[1];
testimage[0] = (Bitmap)pictureBox1.Image;
var ff = bow.Transform(testimage);
ff.ToInt32();
var predicted = tree.Decide(ff);
int i = 1;
for (i = 1; i < sizeofdataset; i++)
{
if (predicted[0] == Convert.ToInt16(workSheet.Cells[i, 3].Value.ToString()))
{
listBox1.SelectedItem = i;
MessageBox.Show("Test" + i);
break;
}
}
MessageBox.Show("Test" + predicted[0]);
pictureBox2.Image = new Bitmap(workSheet.Cells[i, 1].Value.ToString());
watchTest.Stop();
var elapsedMs = watchTest.ElapsedMilliseconds;
MessageBox.Show("Time for Testing is: " + elapsedMs.ToString() + " ms");
}
catch (Exception ex) { MessageBox.Show("Error" + ex); }
}
答案 0 :(得分:0)
请尝试使用带有卡方内核的SVM,而不是ID3或k-NN。
如果您想尝试使用SVM,可以使用example on how to create multi-class kernel SVMs at the bottom of this page (see second example)。你可以用“ChiSquare”替换它所写的“高斯”的所有地方,以便创建一个卡方SVM。
如果您碰巧在{“索引超出数组的范围内。”}正如您在项目的问题跟踪器中指出的那样,我认为您可能没有培训或测试样本。请确保您有足够的训练样本用于所有类,您的班级编号从0开始,输出向量中的最高级别标签对应于number_of_classes - 1,并且在此区间内没有任何相关训练样本的整数。
我发布了一个关于如何使用Accord.NET框架中的卡方内核训练SVM的示例:
// Let's say we have the following data to be classified
// into three possible classes. Those are the samples:
//
double[][] inputs =
{
// input output
new double[] { 0, 1, 1, 0 }, // 0
new double[] { 0, 1, 0, 0 }, // 0
new double[] { 0, 0, 1, 0 }, // 0
new double[] { 0, 1, 1, 0 }, // 0
new double[] { 0, 1, 0, 0 }, // 0
new double[] { 1, 0, 0, 0 }, // 1
new double[] { 1, 0, 0, 0 }, // 1
new double[] { 1, 0, 0, 1 }, // 1
new double[] { 0, 0, 0, 1 }, // 1
new double[] { 0, 0, 0, 1 }, // 1
new double[] { 1, 1, 1, 1 }, // 2
new double[] { 1, 0, 1, 1 }, // 2
new double[] { 1, 1, 0, 1 }, // 2
new double[] { 0, 1, 1, 1 }, // 2
new double[] { 1, 1, 1, 1 }, // 2
};
int[] outputs = // those are the class labels
{
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
2, 2, 2, 2, 2,
};
// Create the multi-class learning algorithm for the machine
var teacher = new MulticlassSupportVectorLearning<ChiSquare>()
{
// Configure the learning algorithm to use SMO to train the
// underlying SVMs in each of the binary class subproblems.
Learner = (param) => new SequentialMinimalOptimization<ChiSquare>()
{
// Estimate a suitable guess for the Gaussian kernel's parameters.
// This estimate can serve as a starting point for a grid search.
UseKernelEstimation = true
}
};
// Configure parallel execution options (or leave it at the default value for maximum speed)
teacher.ParallelOptions.MaxDegreeOfParallelism = 1;
// Learn a machine
var machine = teacher.Learn(inputs, outputs);
// Obtain class predictions for each sample
int[] predicted = machine.Decide(inputs);
// Get class scores for each sample
double[] scores = machine.Score(inputs);
// Compute classification error
double error = new ZeroOneLoss(outputs).Loss(predicted);