Multilabel Image Classification Using Deep Learning--Imbalanced Data

12 次查看(过去 30 天)
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
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 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by