Matlab中的功能和神经网络包

问题描述:

我一直在尝试在Matlab中实现一个能够根据图像特征识别图像的神经网络.我正在尝试使用特征/单词袋方法来获取特征的离散向量,然后将其馈入我的神经网络.

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.

我一直将此示例用作指导- http://in.mathworks.com/help/vision/examples/image-category-classification-using-bag-of-features.html

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

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

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.具体来说,如果您查看示例部分中的代码,它们会绘制一个条形图,其中水平轴表示单词索引,垂直轴表示词汇表中每个单词/功能用来表示图像的分数.

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.

但是,在怀疑训练神经网络之前,您必须用此特征向量表示要训练的每个图像.如果要使用MATLAB的神经网络工具箱,则必须确保每个是一个输入样本,每个是一个功能. featureVector实际上将返回1 x N向量,其中N是要素总数.但是,如果您想更聪明地执行此操作,只需为要转换的所有图像创建一个imageSet:

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

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

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.