Image Classification using Percentage
6 views (last 30 days)
Show older comments
Fatih
on 16 Feb 2025
Commented: Walter Roberson
on 17 Feb 2025
We are working on a project. The goal of the project is to calculate the ratio (in percentage) of musillage in photos. I successfully classified whether a phot has musillage or not (%0 or %100) but not any number in between. The photos are classified using image labeling. The code is attached, woul you please suggest how to improve the working code to cover the percentage of musillages. Two photos of both classes are attached.
Thanks in advance
++
clear all; clc;
imds = imageDatastore("C:\Users\fatih.yigit\OneDrive - ALTINBAS UNIVERSITY\Project 10\project10\Musillage_Photos", ...
IncludeSubfolders=true, ...
LabelSource="foldernames");
numTrainFiles = 25;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,"randomized");
classNames = categories(imdsTrain.Labels);
inputSize = [300 300 3];
numClasses = 2;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(20,50)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
options = trainingOptions("sgdm", ...
MaxEpochs=50, ...
ValidationData=imdsValidation, ...
ValidationFrequency=30, ...
Plots="training-progress", ...
Metrics="accuracy", ...
Verbose=false);
net = trainnet(imdsTrain,layers,"crossentropy",options);
scores = minibatchpredict(net,imdsValidation);
YValidation = scores2label(scores,classNames);
++
5 Comments
Walter Roberson
on 17 Feb 2025
imds = imageDatastore("C:\Users\fatih.yigit\OneDrive - ALTINBAS UNIVERSITY\Project 10\project10\Musillage_Photos", ...
IncludeSubfolders=true, ...
LabelSource="foldernames");
You are getting your labels from the foldernames, not from ground-truth labels.
Accepted Answer
Walter Roberson
on 16 Feb 2025
classNames = categories(imdsTrain.Labels);
That tells us that the class names are categoricals. It is doubtful that the class names happen to be "000%", "001%", "002%" ... "010%", "011%" ... all the way to "099%" and "100%" -- you simply don't have enough training images to be that fine grained. If you do have numbered categories, it is more likely something like "0%", "10%", "20%", up to "90%" then "100%". But categories are internally ordered alphabetically rather than by extracting embedded numbers, so the order would more likely come out as "0%", "10%", "100%", "20%", "30%" up to "90%". The ordering is weak, and so cannot really be used predictively
Now, your images are not internally labeled as to whether parts are musillage or not, so the processing is free to pick out any part to focus on. The processing could, for example, end up focusing on "mountains" and end up ignoring the musillage.
More Answers (0)
See Also
Categories
Find more on Convert Image Type 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!