【问题标题】:Taking results from a trained classifier - Image Processing从经过训练的分类器中获取结果 - 图像处理
【发布时间】:2016-05-14 02:09:02
【问题描述】:

我正在从事一个使用 OpenCV 和 Python 编码的图像性别检测项目。

我找到了this 博客文章和this opencv 教程。在这些站点中,他们建议使用 Fisherfaces 方法和 NearestNeighbor 算法来制作性别分类模型。

这是我的问题:

我是机器学习的新手,所以在这个分类部分之后,我找不到如何将另一个图像应用到这个分类器并采取如下结果形式:

"This person is Male."
"This person is Female."

如何从分类器中获取上述结果?

【问题讨论】:

  • 训练模型后,您应该将输入图像提供给分类器。然后您将预测您的面部图像属于哪个类别。
  • @Eliezer 是的,但是在我将模型保存为 .pkl 文件类型后,如何在 python 中将图像应用于此模型?
  • 你好,我也需要同样的东西,但我对机器学习完全陌生,所以如果你有一个脚本可以完成用 python 编写的技巧,那么你会很棒

标签: python image opencv image-processing machine-learning


【解决方案1】:

分类器使用参考数据进行训练。你给他每个班级的例子(培训)。假设有 500 张女孩的照片和 500 张男孩的照片。你告诉分类器每张图片的性别。然后你给分类器一个未知的图像,他将使用训练好的“知识”来选择一个类(如果可能的话)。

仔细阅读 OpenCV 演示代码。您需要的一切都在里面。

从第 100 行开始:

Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 1];
images.pop_back();
labels.pop_back();
// The following lines create an Fisherfaces model for
// face recognition and train it with the images and
// labels read from the given CSV file.
// If you just want to keep 10 Fisherfaces, then call
// the factory method like this:
//
//      cv::createFisherFaceRecognizer(10);
//
// However it is not useful to discard Fisherfaces! Please
// always try to use _all_ available Fisherfaces for
// classification.
//
// If you want to create a FaceRecognizer with a
// confidence threshold (e.g. 123.0) and use _all_
// Fisherfaces, then call it with:
//
//      cv::createFisherFaceRecognizer(0, 123.0);
//
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels);
// The following line predicts the label of a given
// test image:
int predictedLabel = model->predict(testSample);

在他们使用 CSV 文件加载图像和标签之前。然后仅出于演示目的,他们从矢量中取出最后一张图像,将其从矢量中移除并将其用作被测图像。 (所以被测图像不会在训练数据中)。然后他们使用剩余的图像训练 Fisher 事物并将其应用于图像“testSample”

因此,您需要做的就是将 testSample 替换为您的一张图片,然后根据找到的标签打印出一个句子。

【讨论】:

  • @Piglet 看过这个opencv的demo,但是我不擅长c++,不明白怎么用python写这个“mat”方法。
  • 请注意变量 testSample 的类型。我想在 python 中你可以把 Mat 放在一边。
猜你喜欢
  • 2015-01-17
  • 2015-06-02
  • 1970-01-01
  • 2020-12-25
  • 1970-01-01
  • 2017-10-07
  • 2020-04-02
  • 1970-01-01
  • 2019-05-28
相关资源
最近更新 更多