Azzera filtri
Azzera filtri

Multilabel Image Classification Using Deep Learning--Imbalanced Data

17 visualizzazioni (ultimi 30 giorni)
When I use imbalanced multilabel data to study the example ''openExample('nnet/MultilabelImageClassificationUsingDeepLearningExample') '' ,I found that the loss funtion(CustomBinaryCrossEntropyLossLayer.m, crossentropy) could not be weightd. So I want to use classificationlayer to replace, but classificationlayer could not used in multilabel data.
The crossentropy fuction in supporting file doesn't have Multi-label classificaion with weighted classes.The label is onehotlabel and we use sigmoid instead of softmax.So ,how can I create the outputlayer to achieve Multi-label classificaion with weighted classes?
  3 Commenti
XT
XT il 2 Set 2022
The classficationlayer can assign the ClassWeights and Classes, but the custom layer can't do that.
layer = classificationLayer( ...
'Classes',classes, ...
'ClassWeights',classWeights)
I have modified the custom layer in modified.m, but I'm not sure whether the weights are correctly caculated in the network. The weights' order is the same as the encode order of onehotLabels.
I caculated the weights as follow, Which use the whole Labels of data(not just the train set)
classCounts = sum(onehotLabels,1);
for i=1:numClasses
classFrequency(i) = classCounts(1,i);
classWeights(i) = numel(feature)/(numClasses*classFrequency(i));
end
Tarily
Tarily il 13 Giu 2023
Did you solve this problem? I have the same issue now and I hope to get your help.😭

Accedi per commentare.

Risposta accettata

Varun Sai Alaparthi
Varun Sai Alaparthi il 12 Gen 2023
Hello XT,
There is no direct example or functionality as of MATLAB R2022b to directly do weighted multilabel classification.
But as a workaround you can try building the custom weighted cross entropy layer. Please refer the following link to get more information on this
Or you can try building custom classification layer with Tversky loss which is especially built to handle unbalanced data . You can check the following link for more information on this
Alternatively, there are some ways which can be used to balance the dataset before fitting to the classifier to get the better result. These methods are as follows:
  • Under Sampling- Removing the unwanted or repeated data from the majority class and keep only a part of these useful points. In this way, there can be some balance in the data.
  • Over Sampling- Try to get more data points for the minority class. Or try to replicate some of the data points of the minority class in order to increase cardinality.
  • Generate Data- You can decide to generate synthetic data for the minority class for balancing the data. This can be done using SMOTE method. Below is the link to use SMOTE method-https://www.mathworks.com/matlabcentral/fileexchange/38830-smote-synthetic-minority-over-sampling-technique
Refer to this link for more information on oversampling:
I hope this information helps and please reach out for any further issues.
Sincerely
Varun

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by