How to use sigmoid layer?

조회 수: 2 (최근 30일)
REN Jain
REN Jain 2020년 11월 2일
댓글: Z 2022년 9월 23일
Hello
I am creating a neural network for binary classification.
While executing trainNetwork , this is giving me en error saying that a classificationLayer must be preceded by a softmax layer.
What changes shoul I make? I can use softmax layer with fullyconnectedLayer(2) but using a sigmoidLayer for binary classification will be much more efficint. So after the sigmoidLayer which layer am i supposed to use?
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(1)
sigmoidLayer
classificationLayer];
  댓글 수: 2
Ankit Pasi
Ankit Pasi 2021년 5월 15일
I have the exact same situation and question. Sadly the deep learning community within Matlab is few to none and this like other similar questions go unanswered...
Z
Z 2022년 9월 23일
@REN Jain@Ankit Pasi Were you able solve this issue?

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

답변 (1개)

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2021년 12월 8일
The Classification Layer assign a Class to highest probability using cross-entropy loss. so the output of the layer before classificationLayer should be a descrete probability distribution. output of a fullyConnectedLayer even with some nonlinear activation like sigmoid doesn't create a probability distribution. The softmax function provide such an output.
also you can create your own type of activation function for classification. for example
but in standard creation of deep network in matlab the layer classificationLayer must be preceded by a softmaxlayer as you said. if you want to create your own classification or activation function to yield a probability distribution you should create your own costum layer.
but your set of layers for your problem has some issues. if your network should perform a classification task, your last layer before classification should have same number of output as your classification problem. you want a binary classification which means 2 class, so last fullyConnectedLayer should has 2 output. and finally because of above reason you should use a softmax layer before classificationLayer.
a simple correction for your layers would be :
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(n1) % e.g. n1=10
sigmoidLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
or
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(2)
sigmoidLayer
softmaxLayer
classificationLayer];

카테고리

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