Altering pytorch resnet head from sigmoid to Softmax
I'm new to pytorch. I wrote the below code to do predication using Resnet with Sigmoid for binary classification. I just need to change it to softmax because I might have more than 2 classes.
I understood that pytorch, unlike, Keras, the softmax is in the CrossEntropyLoss. So I'm not sure how could I change the top layer to make the model uses softmax:
model =  torchvision.models.resnet50(pretrained=False)


model.fc = torch.nn.Sequential(
    torch.nn.Linear(
        in_features=2048,
        out_features=1
    ) ,   torch.nn.Sigmoid()
)


model = model.cpu()

and later:
lossFunc=torch.nn.BCELoss(class_weights)


You can try this:
model.fc[1] = torch.nn.Softmax(10)

where 10 are the number of classes, you can put value based on your needs.
