Why does torchvision.models.resnet18 not use softmax? I see image-classification models from torchvision package don't have a softmax layer as final layer. For instance, the following snippet easily shows that the resnet18 output doesn't have a sum = 1, thus the softmax layer is certainly absent.
from torchvision import models
import torch

model = models.resnet18(pretrained=False)

x = torch.rand(8,3,200,200)

y = model(x) 

print(y.sum(dim=1))

So, the question is, why pytorch vision does not put a softmax layer in the end? And how much putting a softmax layer can improve performance? And why?

Whether you need a softmax layer to train a neural network in PyTorch will depend on what loss function you use. If you use the torch.nn.CrossEntropyLoss, then the softmax is computed as part of the loss. From the link:

The loss can be described as:
$$
\text{loss}(x,class) = −\log\left(\frac{\exp⁡(x[class])}{\sum_j \exp(x[j])}\right)
$$

This loss is just the concatenation of a torch.nn.LogSoftmax followed by the torch.nn.NLLLoss loss. From the documentation of torch.nn.CrossEntropyLoss:

This criterion combines LogSoftmax and NLLLoss in one single class.

and from the documentation of torch.nn.NLLLoss:

Obtaining log-probabilities in a neural network is easily achieved by adding a LogSoftmax layer in the last layer of your network. You may use CrossEntropyLoss instead, if you prefer not to add an extra layer.

It seems that the developers of these pretrained models had the torch.nn.CrossEntropyLoss in mind when they were creating them.
