10 fold validation using bag of features
Show older comments
I was wondering how I can implement a Bag of Features Algorithm on Matlab but using 10-fold Cross Validation on the training and testing sets and finding the average accuracy from this. Below is the code I have attempted to implement.
% code
ims = imageDatastore(fullfile(setDir,categories),'LabelSource',...
'foldernames');
tbl = countEachLabel(ims);
minimumSetCount = min(tbl{:,2}); %find the smallest amount of images in the categories
ims = splitEachLabel(ims,minimumSetCount, 'randomize');
[trainingSet, testSet] = splitEachLabel(ims, 0.5, 'randomize'); %train only 30% of images
p=10;
cv = crossvalind('Kfold', ims, p);
for i=1:p
testSet = (cv == i);
trainingSet = ~testSet;
SURFFcn = @exampleBagOfFeaturesExtractor;
bag = bagOfFeatures(trainingSet, 'CustomExtractor', SURFFcn, 'VocabularySize', 500, 'StrongestFeatures', 0.5);
categoryClassifier = trainImageCategoryClassifier(trainingSet,bag);
confMatrix = evaluate(categoryClassifier, testSet);
end
However, I receive this error when trying to implementing this. It says:
Array formation and parentheses-style indexing with objects of class 'matlab.io.datastore.ImageDatastore' is not allowed. Use objects of class 'matlab.io.datastore.ImageDatastore' only as scalars or use a cell array.
Can anyone help me to find a solution to this problem? Thanks
Answers (0)
Categories
Find more on Image Category Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!