How to use a bag of features object to train a Random fores classifier?

1 次查看(过去 30 天)
Hello, I'm using categoryClassifier = trainImageCategoryClassifier(trainingSet, bag) to train ans SVM model. bag is a bag of visual words. How can I derive a TreeBagger model instead of SVM?

采纳的回答

Uttiya Ghosh
Uttiya Ghosh 2020-7-14
编辑:Uttiya Ghosh 2020-7-15
Hi Shai,
From my understanding, you want to know how to convert a bag of features into a table of features so that it can be used to train a TreeBagger model. PFB the code that will help you in the conversion process. Here I have used a datatore of 12 images. I have randomly selected 75% of the images for training and remaining for testing my model. I have used 5 trees in my tree bagger model.
setDir = fullfile(toolboxdir('vision'),'visiondata','imageSets');
imds = imageDatastore(setDir,'IncludeSubfolders',true,'LabelSource',...
'foldernames');
[imdsTrain,imdsTest] = splitEachLabel(imds,0.75,'randomize');
bagTrain = bagOfFeatures(imdsTrain);
bagTest = bagOfFeatures(imdsTest);
featureVectorTrain = encode(bagTrain, imdsTrain);
featureVectorTest = encode(bagTest, imdsTest);
B = TreeBagger(5,featureVectorTrain,imdsTrain.Labels);
imdsPred = predict(B,featureVectorTest);
acc = (nnz(imdsPred == imdsTest.Labels))/length(imdsTest.Labels);
For more information, refer to the following links.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by