0

I am currently training a ResNet18 model with a custom optimizer in PyTorch.

I am using CrossEntropyLoss() and the ResNet18 model from PyTorch. In tensorflow the outputs are of the desired shape, but in pytorch it is necessary to find the argmax of the predicted labels in order to find the accuracy.

If my batch size = 64 with the resnet model, why is the predicted label of shape [64, 1000]?

What do the 1000 values correspond to?

1 Answer 1

1

The predicted quantity is not "label", it is the probability (soft score) of the input being one of 1000 classes.

The output of (64, 1000) contains a 1000 length vector for each input in a batch. If you want discrete labels (i.e. 0 to 999), perform an argmax over it

labels = torch.argmax(output, 1) 

By argmax over each probability vector, we compute which class (among 1000) has the highest probability for the input.

Sign up to request clarification or add additional context in comments.

5 Comments

I am using cifar10 which doesn't have 1000 classes.
Then you have to make the last layer 10 and train the network
does the torchvision.models.resnet18() model not work for this? Do I need to make it myself?
I just switched to a different model and it is working. Thank you
yes it does, just pass num_classes=10 in the constrcutor, i.e. model = ResNet(num_classes=10)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.