Classification problem in pytorch with loss function CrossEntropyLoss returns negative output in prediction

I am trying to train and predict SVHN dataset (VGG architecture). I get very high validate/test accuracy by just getting the largest output class. However, the output weights are of large positive and negative numbers. Are they supposed to parsed as exp(output)/sum(exp(output)) to be converted to probability? Thank you!

Topic pytorch cnn

Category Data Science


The numbers to which you are referring are probably the logits of the NN. The logits have to be transformed using a activation function which could be:

  • Softmax ( which you showed ) for classification tasks.

  • Linear activation function for regression tasks.

Softmax activation function :

The mathematical notion is as follows:

$\Large S( y_i ) = \frac{ e^{y_i}}{ \sum e^{y_i} }$

It converts the logits to class probabilities that sum to 1. It is widely used in multiclass classification problems.

CNNs for classification need to produce class probabilities which are produced by a softmax activation function at the output layer.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.