Multilabel Image Classification Using Deep Learning--Imbalanced Data

조회 수: 9 (최근 30일)
XT
XT 2022년 8월 31일
댓글: Tarily 2023년 6월 13일
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
XT
XT 2022년 9월 2일
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 2023년 6월 13일
Did you solve this problem? I have the same issue now and I hope to get your help.😭

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

채택된 답변

Varun Sai Alaparthi
Varun Sai Alaparthi 2023년 1월 12일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by