Sm1
Sm1

Reputation: 570

Is there a difference in the output (final layer) between NN and CNN?

In the case of multiclass classification, if the number of classes are N, then a NN has N output nodes. However, for binary classification using NN, the output node is only one.

Confusion: For binary classification using CNN with integer valued labels (0/1 or 1/2), would the number of output nodes be 2? Or with one-hot encoding scheme 0-0, 0-1,1-0 and 1-1 the number of output nodes would be 2 otherwise 1 output node.

This confusion also comes from the implementation syntax. In the code below using CNN, for binary classification I have to mention numClasses =2 when the classes are integer valued 0/1 or 1/2. Does that mean that there are 2 output nodes? Please correct me where wrong.

inputSize = [28 28 1];
numClasses = 2;

layers = [
    imageInputLayer(inputSize)
    convolution2dLayer(5,20)
    batchNormalizationLayer
    reluLayer
    fullyConnectedLayer(numClasses)
    softmaxLayer
    classificationLayer];

Upvotes: 1

Views: 136

Answers (1)

Himanshu Chaudhary
Himanshu Chaudhary

Reputation: 66

The implementation syntax is correct. But for binary classification use just sigmoid activation instead of softmax with just one node for the last layer.

When sigmoid is used, then number of output nodes is 1 and one hot encoding is not used. Output of sigmoid is probability and if probability is greater 0.5 output class is class 1 and otherwise class 2.

When softmax is used, then number of output nodes is 2 and one hot encoding is required. Both output nodes represents probabilities of each respective class.

Upvotes: 2

Related Questions