Image Classification using Percentage

조회 수: 4 (최근 30일)
Fatih
Fatih 2025년 2월 16일
댓글: Walter Roberson 2025년 2월 17일
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
Fatih
Fatih 2025년 2월 17일
Actually I labeled the mucillage regions manually using the image labeler.
Walter Roberson
Walter Roberson 2025년 2월 17일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2025년 2월 16일
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.
  댓글 수: 1
Fatih
Fatih 2025년 2월 17일
Actually I labeded photos using Imagelabeler while selecting musillage areas. They may not be perfect but gives an idea. So if there is better way, I am also comfortable to ignore what I did and start from scratch including more photos.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by