I am trying to add a softmax layer to a vit-b
model with 10 outputs.
While it works calling torch.softmax
directly on the model output, I do not get softmax output when adding the softmax as a fully connected layer:
import torchvision
import torch
torch.manual_seed(1)
image = torch.rand(1,3,224,224)
model = torchvision.models.vit_b_16(weights="DEFAULT")
model.heads.head = torch.nn.Linear(in_features=768, out_features=10, bias=True)
model.fc = torch.nn.Softmax(10)
model(image)
This does not seem to apply softmax, the output is
tensor([[ 0.0204, -0.0550, -0.7651, -0.2418, 0.0715, 0.1525, -0.1907, -0.1199,
0.0427, -0.2585]], grad_fn=<AddmmBackward0>)
What am I doing wrong?