袋的单词培训和测试opencv,matlab [英] Bag of words training and testing opencv, matlab

查看:208
本文介绍了袋的单词培训和测试opencv,matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SIFT功能在opencv中实现Bag Of Words,以便对特定数据集进行分类。到目前为止,我一直是苹果集群描述符并生成词汇。据我所知,我必须训练SVM ...但我有一些问题,我真的很困惑他们。主要问题是实现背后的概念,这些是我的问题:

I'm implementing Bag Of Words in opencv by using SIFT features in order to make a classification for a specific dataset. So far, I have been apple to cluster the descriptors and generate the vocabulary. As I know, I have to train SVM ... but i have some questions which i'm really confused about them. The major problem is the concept behind the implementations, these are my questions:

1-当我提取功能然后创建词汇表时,我是否应该为所有功能提取功能对象(假设有5个对象)并将它们放在一个文件中,所以我将它们全部放在一个包含所有单词的词汇表文件中?以及在我进行分类时如何将它们分开?

1- When I extract the features and then create the vocabulary, shall I extract the features for all the objects (let's say 5 objects)and put them in one file, so I make all of them in a one vocabulary file that has all the words? and how I will separate them later on when I do the classification?

2-如何实施SVM?我知道openCV中使用的函数但是怎么做?

2- How to implement the SVM? I know the functions that are used in openCV but how?

3-我可以在MATLAB中完成工作,我的意思是SVM培训的实现,但是在那里任何可用的代码可以指导我完成我的工作?我看过Andrea Vedaldi使用的代码,这里但他每次只使用一个班级,另一个问题是他没有展示如何创建他在练习中使用的.mat文件。我能找到的所有其他实现,他们都没有使用SVM。那么,你能指导这一点吗?

3- I can do the work in MATLAB, which I mean the implementation of the SVM training, but is there any code available that can guide me through my work? I have seen the code used by Andrea Vedaldi, here but he is working only with one class each time and another issue that he is not showing how to create the .mat file that he's using in his exercises. All other implementations that I could find, they are not using SVM. So, can you guide in this point too!

谢谢你

推荐答案

< h2>本地功能

使用SIFT时,通常需要提取本地功能。这意味着什么?您拥有自己的图像,然后从该图像中找到要从中提取局部特征向量的点。局部特征向量只是由数值组成的向量,该数值描述从中提取它的图像区域的视觉信息。虽然可以从图像A中提取的局部特征向量的数量不需要与可以从图像B中提取的特征向量的数量相同,但是局部特征向量的数量分量(即其维数)始终是同样。

Local features

When you work with SIFT, you usually want to extract local features. What does that means? You have your image and from this image you will locate points from which you will extract local feature vectors. A local feature vector is just a vector consisting of numerical values that describes the visual information of the image region from which it was extracted. Although the number of local feature vectors that you can extract from image A does not need to be the same as the number of feature vectors that you can extract from image B, the number components of a local feature vector (i.e. its dimensionality) is always the same.

现在,如果你想使用你的本地特征向量来分类你有问题的图像。在传统的图像分类中,每个图像由全局特征向量描述,在机器学习的上下文中,可以将其视为一组数字属性。但是,当您提取一组局部特征向量时,您没有图像分类所需的每个图像的全局表示。可以用来解决这个问题的技巧就是一袋词,也称为视觉词袋(BoW)。

Now, if you want to use your local feature vectors to classify images you have a problem. In traditional image classification, each image is described by a global feature vector, which, in the context of machine learning, can be seen as a set of numerical attributes. However, when you extract a set of local feature vectors you don't have a global representation of each image which is required for image classification. A technique that can be employed to solve this problem is the bag of words, also known as bag of visual words (BoW).

这是(非常)简化的BoW算法:

Here's the (very) simplified BoW algorithm:


  1. 提取SIFT本地特征来自您的图像集的向量;

  1. Extract the SIFT local feature vectors from your set of images;

将所有这些局部特征向量放入一个集合中。此时,您甚至不需要存储从中提取每个局部特征向量的图像;

Put all this local feature vectors into a single set. At this point you don't even need to store from which image each local feature vector was extracted;

应用聚类算法(例如k-means)一组局部特征向量,以便找到质心坐标并为每个质心分配一个id。这组质心将是您的词汇;

Apply a clustering algorithm (e.g. k-means) over the set of local feature vectors in order to find centroid coordinates and assign an id to each centroid. This set of centroids will be your vocabulary;

全局特征向量将是一个直方图,用于计算每个图像中每个质心出现的次数。要计算直方图,请找到每个局部特征向量的最近质心。

The global feature vector will be a histogram that counts how many times each centroid occurred in each image. To compute the histogram find the nearest centroid for each local feature vector.



图像分类



这里我假设您的问题如下:

Image Classification

Here I am assuming that your problem is the following:


您输入一组带标签的图像以及一组未标记的
图像,您希望根据其可视
外观分配标签。假设你的问题是对风景摄影进行分类。
您的图像标签可以是,例如,mountains,beach或
forest。

You have as input a set of labeled images and a set of non-labeled images which you want to assign a label based on its visual appearance. Suppose your problem is to classify landscape photography. You image labels could be, for example, "mountains", "beach" or "forest".

从每个图像中提取的全局特征向量(即它的视觉词袋)可以看作是一组数字属性。表示每个图像的视觉特性的这组数值属性和相应的图像标签可用于训练分类器。例如,您可以使用 Weka 等数据挖掘软件。 SVM的一种实现,称为SMO,用于解决您的问题。

The global feature vector extracted from each image (i.e. its bag of visual words) can be seen as a set of numerical attributes. This set of numerical attributes representing the visual characteristics of each image and the corresponding image labels can be used to train classifier. For example, you could use a data mining software such as Weka, which has an implementation of SVM, known as SMO, to solve your problem.

基本上,您只需根据 ARFF文件格式,基本上是全局特征向量的CSV,后跟图像标签。

Basically, you only have to format the global feature vectors and corresponding image labels according to the ARFF file format, which is, basically, a CSV of global feature vectors followed by image label.

这篇关于袋的单词培训和测试opencv,matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆