Image Classification using Percentage

24 ビュー (過去 30 日間)
Fatih
Fatih 2025 年 2 月 16 日 8:42
コメント済み: Walter Roberson 2025 年 2 月 17 日 15:48
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 日 10:16
Actually I labeled the mucillage regions manually using the image labeler.
Walter Roberson
Walter Roberson 2025 年 2 月 17 日 15:48
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 日 18:54
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 日 9:11
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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by