Overfitting Issue

Mahbubcse: <p>I am estimating age from face images where the number of classes is 101(0…100). I made 3 subgroup where group1(0-15),group2(16-64) and group3(65+). The training &amp; validation accuracy of group1 &amp; 3 is  90% &amp; 75% respectively, but group2 validation performance is about (30%) whereas training accuracy is 90%. Noted that, group2 has almost 40k training images and is almost balanced.  I have tried with different pretrained model(resnet, squeezenet, inception resnet v1), scratch models(resnet,vgg16, ), attention models (Squeeze and Excitation, Block Attention module ), but none of them work fine. I have changed the hyper parameters like (weight decay, learning rate scheduler). Can anyone suggest to me which models can work or how I can solve this problem?<br>
FYI: Group2 belongs 49 classes. I am estimating the real age through classification.</p>

KFrank: <p>Hi Mahbubul!</p>
<aside class="quote no-group quote-modified" data-username="Mahbubcse" data-post="1" data-topic="134751" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mahbubcse/48/43180_2.png" class="avatar"> Mahbubcse:</div>
<blockquote>
<p>I am estimating age from face images where the number of classes is 101(0…100).<br>
…<br>
I am estimating the real age through classification.</p>
</blockquote>
</aside>
<p>If you are working on this as a semi-realistic problem (in contrast to<br>
a pure learning exercise), I would strongly suggest that you treat this<br>
as regression problem rather than a classification problem.</p>
<p>You would have your final layer be a <code>Linear</code> with <code>out_features = 1</code>,<br>
and the output value would be the predicted age.  Your <code>target</code><br>
(ground-truth annotation) would be the actual age.  Then use something<br>
like <code>MSELoss</code> as your loss criterion.</p>
<p>If the true age is <code>50</code> then classifying the image as class <code>49</code> or <code>51</code><br>
is no better or worse than classifying it as <code>0</code> or <code>100</code>.  So in training<br>
you would be throwing away the (very useful) information that your<br>
prediction was almost exactly right (even though not spot on).</p>
<p>On the other hand, using a regression-type loss (such as <code>MSELoss</code>)<br>
would heavily penalize a prediction of <code>0</code>, but only modestly disfavor a<br>
prediction of <code>49</code> in comparison with the correct result of <code>50</code> (and this<br>
is logically what you want).</p>
<p>Best.</p>
<p>K. Frank</p>

Mahbubcse: <p>Thank you very much for your comprehensive reply.<br>
Actually, after the classification, I calculate the expected value(age) and don’t think about only top1 prediction.<br>
expected age = sum(predicted probability * corresponding label)</p>
<p>I will try according to your suggestion.  Thank you.</p>

Sunday114: <p>Overfitting is much more general than what you describe. What you describe is specifically the case for some neural networks that keep fitting better and better on your training data even though later on it might only be noise that it is fitting to. In general, overfitting means that your model is learning not just signal but also noise which hurts generalization<a href="https://www.prepaidgiftbalance.vip/www-prepaidgiftbalance-com/" rel="noopener nofollow ugc">.</a></p>