I am building a CNN model for age classification. Assuming age of a person is between 1-100, my last Linear Layer contains 100 output neuron.
Now i want to find an appropriate loss function for this classification problem.
I dont wish to use Regression
- I cannot use MSE or BCE loss because they only works element wise so unsuitable as if actual age is 25 then there will be same loss for predicted age 26 and 50. (Prediction will be 100 element vector as last layer has 100 neurons.)
- I found about Hinge Loss and Cosine Proximity Loss. But i dont think they can be used in this type of classifiaction either because they are only finding similarity between two vectors without giving any importance or weight to nearby actual-predicted pairs (ex actual age 25 and predicted age 26 should have a very low loss)
Can anyone suggest me a suitable loss function (Preferrably in Pytorch) for this classification problem?
Lets say I want a Loss Function (L(predicted, actual)) such that (Assuming for 5 class classification)
let actual = [0,0,1,0,0] L([0,0,1,0,0], actual) < L([0,1,0,0,0], actual) < L([1,0,0,0,0], actual) L([0,0,1,0,0], actual) < L([0,0,0,1,0], actual) < L([0,0,0,0,1], actual)