Bag of features and Neural Networks in Matlab

会有一股神秘感。 提交于 2019-12-04 09:06:36
rayryeng - Reinstate Monica

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!