Using Weighted Classes in CNN

2 次查看(过去 30 天)
In trying to set up my CNN layers with weighted classes I am getting an error that states:
"Error using classificationLayer>iParseInputArguments (line 58)
'ClassWeights' is not a recognized parameter. For a list of valid name-value pair arguments, see the
documentation for this function."
I am unsure if I'm using the class weights incorrectly. The following are the layers of my network:
classes = ["0","1"];
classWeights = 1./countcats(train_output);
classWeights = classWeights'/mean(classWeights);
layers = [
imageInputLayer([480 1 1])
convolution2dLayer([102 1],3,'Stride',1)
batchNormalizationLayer
leakyReluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
convolution2dLayer([24 1],10,'Stride',1)
batchNormalizationLayer
leakyReluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
convolution2dLayer([11 1],10,'Stride',1)
batchNormalizationLayer
leakyReluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
convolution2dLayer([9 1],10,'Stride',1)
batchNormalizationLayer
leakyReluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
fullyConnectedLayer(30)
fullyConnectedLayer(10)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer('Classes',classes,'ClassWeights',classWeights)];
This error occurs with and without classes present in the brackets.
  1 个评论
Darrien Walters
Darrien Walters 2021-3-14
For further clarification i dont believe my layers are the real issue as i have run it before without the weighted classes and got no issue it occurs when i try to add class weights to the classification layer and i am unsure why if i am using the function wrong

请先登录,再进行评论。

采纳的回答

Rishik Ramena
Rishik Ramena 2021-3-21
The 'ClassWeights' property for the classificationLayer has been introduced in MATLAB R2021a. So if you are running a version prior to this, you are supposed to get this error. Please find the documentation for your installed MATLAB version here.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by