How do you do multi-class classification with a CNN network?

Currently I have a CNN network with a the classification layer.
net = alexnet;
layersTransfer = net.Layers(1:end-3);
numClasses = 5;
layers = [
layersTransfer
fullyConnectedLayer(numClasses,'Name', 'fc','WeightLearnRateFactor',1,'BiasLearnRateFactor',1)
softmaxLayer('Name', 'softmax')
classificationLayer('Name', 'classOutput')];
There are 5 different classes and each image can have multiple classes. However I can not find a way to train a network where each image has more than one possible class. How can I change my network so I can train it with data where there are multiple labels?

 採用された回答

Mahesh Taparia
Mahesh Taparia 2021 年 4 月 19 日

1 投票

Hi
As per your problem, I am assuming you are having multiple categorical objects in a single image. So the problem is no longer an image classification, it is an object detection problem. You can refer to the documentation of object detection, here are some useful links:
Hope it will help!

4 件のコメント

Michael Bilenko
Michael Bilenko 2021 年 4 月 22 日
I am not trying to do object detection. I am looking at medical images and each image could have multiple diseases so I would need an output for each class.
Mahesh Taparia
Mahesh Taparia 2021 年 4 月 22 日
Usually an image is assigned as 1 label in case of image classification. So we use softmax classifier at the last layer. One possible approach for your problem is to replace that softmax layer with sigmoid layer with 5 inputs and 5 outputs (as numClasses = 5). It will give the probability of each class in that image. Use the custom loss layer at the end of the network (with classification loss of 5 classes) while doing training. This is a possible approach of multi label classification.
Michael Bilenko
Michael Bilenko 2021 年 4 月 24 日
Thanks for the suggestion. How do I implement a custom loss layer?

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by