带散列的 SURF
SURF with hashing
我想问你是否可以使用 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); }
}
请尝试使用带有卡方内核的 SVM,而不是 ID3 或 k-NN。
如果您想尝试 SVM,可以使用 example on how to create multi-class kernel SVMs at the bottom of this page (see second example)。您可以用 "ChiSquare" 替换所有写 "Gaussian" 的地方,以创建卡方 SVM。
如果您碰巧在 {"Index was outside the bounds of the array."} 中 运行 正如您在项目的问题跟踪器中指出的那样,我认为您可能有一个 class 没有训练或测试样本。请确保您有足够的训练样本用于所有 classes,您的 class 数字从 0 开始,输出向量中最高的 class 标签对应于 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);
我想问你是否可以使用 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); }
}
请尝试使用带有卡方内核的 SVM,而不是 ID3 或 k-NN。
如果您想尝试 SVM,可以使用 example on how to create multi-class kernel SVMs at the bottom of this page (see second example)。您可以用 "ChiSquare" 替换所有写 "Gaussian" 的地方,以创建卡方 SVM。
如果您碰巧在 {"Index was outside the bounds of the array."} 中 运行 正如您在项目的问题跟踪器中指出的那样,我认为您可能有一个 class 没有训练或测试样本。请确保您有足够的训练样本用于所有 classes,您的 class 数字从 0 开始,输出向量中最高的 class 标签对应于 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);