[PYTHON] About the matter that softmax is not needed at the end of Torchvision model.

background

As you can see from the code below, the final layer is Liner and does not include the softmax layer. https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py

I thought, "Well, is this okay?"

Reason

It was all written below. https://discuss.pytorch.org/t/torchvision-models-dont-have-softmax-layer/18071

When learning, nn.CrossEntoropyLoss () is used, but it is not necessary because it consists of nn.LogSoftmax and nn.NLLLoss..

When inferring, if you want the probability of each class, you need nn.functional.softmax (), but if you want to predict, you can omit the idx of the largest value in torch.max etc.

At the time of classification, I thought that the final layer was softmax due to brain death, but if I think about it carefully, it is only necessary for loss calculation, so I thought "I see."

Recommended Posts

About the matter that softmax is not needed at the end of Torchvision model.
About the matter that the contents of Python print are not visible in docker logs
Grep so that grep does not appear at the time of grep
Decorator that displays "FIN method name" at the end of the method
About the matter that nosetests does not pass when __init__.py is created in the project directory
Python Basic Course (at the end of 15)
The update of conda is not finished.
It seems that the version of pyflakes is not the latest when flake8 is installed
About the problem that the python version of Google App Engine does not mesh
About the matter that was worried about sampling error
The value of pyTorch torch.var () is not distributed
Send Gmail at the end of the process [Python]
Remove specific strings at the end of python
About "RuntimeWarning: Pickled model instance's Django version is not specified"
About the matter that torch summary can be really used when building a model with Pytorch
The result of analyzing Kant's "criticism of judgment" that I did not read at all was interesting