apple / ml-cvnets

CVNets: A library for training computer vision networks
https://apple.github.io/ml-cvnets
Other
1.76k stars 225 forks source link

classification mobilevit_v2 model,where can I find softmax activation layer? #66

Closed chenying99 closed 1 year ago

chenying99 commented 1 year ago

cvnets/models/classification/mobilevit_v2.py the last layer as follow:

https://github.com/apple/ml-cvnets/blob/main/cvnets/models/classification/mobilevit_v2.py#L90

self.classifier = nn.Sequential( GlobalPool(pool_type=pool_type, keep_dim=False), LinearLayer(in_features=out_channels, out_features=num_classes, bias=True), )

where can I find softmax activation layer? thank you

farzadab commented 1 year ago

Since computing the loss after SoftMax is numerically unstable, usually the softmax is not found in the models themselves and this step usually happens implicitly in the loss function.

Take a look at the documentation of CrossEntropyLoss in PyTorch. It takes logits as input, not actual probabilities. You can compare that with NLLLoss which does expect probabilities.

Please note that although SoftMax is not added during training, it can be added in the inference/export step as needed.

chenying99 commented 1 year ago

OK, thank you for your reply, I will refer to relevant documents

farzadab commented 1 year ago

Np. Closing the issue. Feel free to reopen if need be.