Extracting features from pretrained network and feed them into a softmax layer for calssification

2 次查看(过去 30 天)
I use ResNet50 to extract features from images then I want to feed these features into softmax layer for classification but I don't know how to feed these features into softmax layer. I used fitcecoc for classification but it didn't give me the good results for that reason I want to use softmax layer rather than fitcecoc.
Here is my code:
imds = imageDatastore('chromosomes','IncludeSubfolders',true,'LabelSource','foldernames');
[trainingSet,testSet] = splitEachLabel(imds,0.8, 'randomize');
net = resnet50 ();
imageSize = net.Layers(1).InputSize;
augmentedTrainingSet = augmentedImageDatastore(imageSize, trainingSet,'ColorPreprocessing','gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize, testSet,'ColorPreprocessing','gray2rgb');
featureLayer = 'activation_43_relu';
trainingFeatures = activations(net, augmentedTrainingSet, featureLayer, 'OutputAs','rows');
testFeatures = activations(net, augmentedTestSet, featureLayer,'OutputAs','rows');
trainingLabels = trainingSet.Labels;
testLabels = testSet.Labels;
classifier = fitcecoc(trainingFeatures,trainingLabels);
YPred = predict(classifier,testFeatures);
accuracy = mean(YPred == testLabels)

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by