at the last 2 lines how does it work? as in why do we need to exp?
i thought we can just
and we will obtain the result?
because when we
model(img).size() the output is
torch.Size([1, 10]) which is the 10 categories and the highest is the predicted result?
model = nn.Sequential(nn.Linear(784, 128),
criterion = nn.NLLLoss()
optimizer = optim.SGD(model.parameters(), lr=0.003)
- snip some codes -
images, labels = next(iter(trainloader))
img = images.view(1, 784)
Turn off gradients to speed up this part
logps = model(img) #input an image after re-shaped
Output of the network are log-probabilities, need to take exponential for probabilities
ps = torch.exp(logps) # <-- same effect
ps = F.softmax(logps,dim=0) <–same effect
view_classify(img.view(1, 28, 28), ps)