Matlab中的一些特征和神经网络(Bag of features and Neural Networks in Matlab)

编程入门 行业动态 更新时间:2024-10-26 18:15:38
Matlab中的一些特征和神经网络(Bag of features and Neural Networks in Matlab)

我一直在尝试在Matlab中实现一个能够根据其特征识别图像的神经网络。 我试图使用Bag of features / words方法获得一个离散的特征向量,然后我可以将其输入我的神经网络。

我一直在使用这个例子作为指南 - http://in.mathworks.com/help/vision/examples/image-category-classification-using-bag-of-features.html

代码中的一行(featureVector = encode(bag,img);)计算图像中的单词出现次数。 我可以使用这个“featurevector”矩阵来训练我的神经网络吗? 我是否必须对训练集中的每个图像进行编码?

I've been trying to implement a neural network in Matlab that is capable of recognizing images based on their features. I am attempting to use the Bag of features/words approach to obtain a discrete vector of features that I can then feed into my neural network.

I have been using this example as a guide - http://in.mathworks.com/help/vision/examples/image-category-classification-using-bag-of-features.html

One line in the code (featureVector = encode(bag, img);) counts the word occurrences in an image. Could I use this "featurevector" matrix to train my neural network? And would I have to encode every single image in my training set?

最满意答案

是的,这当然是可能的。 通过查看示例,训练数据集是一组图像,您将找到500个“单词”/功能的常用词汇表,其中描述了所有这些词汇的充分性。 通过使用featureVector = encode(bag, img); ,你正在做的是你正在确定每个单词的哪个部分存在来描述输入图像img 。 具体来说,如果您查看该示例部分中的代码,它们会绘制条形图,其中水平轴表示单词索引,垂直轴表示词汇表中每个单词/特征用于表示该图像的分数。

具体来说,这是生成的条形图(取自链接):

因此,类似的图像应该用相似的特征/单词来描述,因此您当然可以将其用作神经网络的输入。

但是,在您训练神经网络之前,如您所怀疑的那样,您必须使用此特征向量表示您希望训练的每个图像。 如果您打算使用MATLAB的神经网络工具箱,则必须确保每都是输入样本,每都是一个特征。 featureVector实际上会返回1 x N向量,其中N是featureVector的总数。 但是,如果你想更聪明地做到这一点,只需创建一个你想要转换的所有图像的imageSet : http : //www.mathworks.com/help/vision/ref/imageset-class.html ,然后使用一个调用encode以创建所需的特征矩阵:

imgFolder = '...'; %// Specify image folder here imgSet = imageSet(imgFolder); %// Create image set featureMatrix = encode(bag,imgSet).'; %// Encode the images - Make sure you transpose

结果将是M x N矩阵,其中M是您拥有的输入图像的总数, N是N的总数。 要尊重神经网络工具箱,您必须转置此矩阵,因为每需要是输入样本,而不是每行。

Yes that's certainly possible. By looking at the example, the training dataset is a set of images and you are finding a common vocabulary of 500 "words" / features that describes all of them with adequacy. By using featureVector = encode(bag, img);, what you are doing is you are determining what fraction of each word exists to describe the input image img. Specifically, if you look at the code in that example section, they plot a bar graph where the horizontal axis represents the word index and the vertical axis represents what fraction each word / feature in the vocabulary is used to represent that image.

Specifically, this is the bar graph that gets produced (taking from the link):

Therefore, similar images should be described with similar features / words and so you could certainly use this as input into your neural network.

However, before you train your neural network, as you suspected, you must represent every image you wish to train with this feature vector. If you intend to use MATLAB's neural network toolbox, you must make sure that each column is an input sample and each row is a feature. featureVector would actually return a 1 x N vector where N is the total number of features. However, if you want to do this more smartly, simply create an imageSet of all of the images you want to transform: http://www.mathworks.com/help/vision/ref/imageset-class.html, then use one call to encode to create this desired feature matrix:

imgFolder = '...'; %// Specify image folder here imgSet = imageSet(imgFolder); %// Create image set featureMatrix = encode(bag,imgSet).'; %// Encode the images - Make sure you transpose

The result will be a M x N matrix where M is the total number of input images you have and N is the total number of features. To respect the neural networks toolbox, you must transpose this matrix because each column needs to be an input sample, not each row.

更多推荐

本文发布于:2023-07-22 01:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1215519.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:神经网络   特征   Matlab   Bag   Networks

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!