Hi folks, I'm trying to pass my images for classification to a CNN and then move each image (after being classified) to a folder based on its classification. Currently, I don't get any errors but the code just compiles without any outputs…Any help would be most appreciated!
for k = 1:fileNumber currentImage = fullfile(imageList(k).folder, imageList(k).name); img = imread(currentImage); labelName = classify(DaveNet, img); switch labelName case 'Anisotropy' movefile(currentImage, AnisotropyClassificationPath); case 'Isotropy' movefile(currentImage, IsotropyClassificationPath); case 'Filler' movefile(currentImage, FillerClassificationPath); otherwise movefile(currentImage, BadCropsClassificationPath); end end
My CNN for reference:
imds = imageDatastore(TrainingDatasetPath, 'IncludeSubfolders',true,... 'LabelSource','foldernames');labelCount = countEachLabel(imds)numTrainFiles = 500;[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');layers = [ imageInputLayer([227 227 3]) convolution2dLayer(3, 8, 'Padding', 'same') batchNormalizationLayer reluLayer maxPooling2dLayer(2, 'Stride', 2) convolution2dLayer(3, 16, 'Padding', 'same') batchNormalizationLayer reluLayer maxPooling2dLayer(2, 'Stride', 2) convolution2dLayer(3, 32, 'Padding', 'same') batchNormalizationLayer reluLayer maxPooling2dLayer(2, 'Stride', 2) convolution2dLayer(3, 64, 'Padding', 'same') batchNormalizationLayer reluLayer maxPooling2dLayer(2, 'Stride', 2) convolution2dLayer(3, 128, 'Padding', 'same') batchNormalizationLayer reluLayer fullyConnectedLayer(4) softmaxLayer classificationLayer];options = trainingOptions('sgdm','InitialLearnRate',0.001, ... 'MaxEpochs', 5,'Shuffle','every-epoch', ... 'ValidationData',imdsValidation,'ValidationFrequency',30, ... 'Verbose',false, 'Plots','training-progress');net = trainNetwork(imdsTrain, layers, options);YPred = classify(net, imdsValidation);YValidation = imdsValidation.Labels;accuracy = sum(YPred == YValidation)/numel(YValidation)
Best Answer