Is this refer to overfitting?

Weng_zhiqiang: <p>Sorry to ask this stupid question. But I have trid a lot and I still can’t understand how could this happen.<br>
First of all, I try to use resnet-18 working on age classifier. And the age class is five. I selected the CACD dataset which preprocesses by mtcnn (<strong>crop and align</strong>). Then I split the dataset to two groups and 0.9 for training, others for testing. And some settings are as follow:<br>
optimizer: Adam;<br>
Learning_rate: 1e-5;<br>
BZ: 128;<br>
Actually, at first, the val acc is increased as I expect. But when the acc arrived at 50%. It keeped the acc for the whole training. Yeah, the training acc is 98%, but it still 50%. I’m not sure if my code of training is wrong. Since the val didn’t change. Then, I used training data to train, also to val. Indeed, it works very good, which means there maybe are no wrongs with my training code? And there is my code of my “stupid” model.</p>
<p>def <em>resnet(arch, block, layers, pretrained, progress, **kwargs):<br>
model = ResNet(block, layers,  **kwargs)<br>
if pretrained:<br>
state_dict = torch.load(RESNET_MODEL_PATH)<br>
for key, value in state_dict.items():<br>
if ‘fc’ in key:<br>
continue<br>
model.state_dict()[key].copy</em>(state_dict[key])<br>
return model</p>
<p>class AgeClassifier(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(AgeClassifier, self).<strong>init</strong>()<br>
self.resnet = _resnet(‘resnet18’, BasicBlock, [2, 2, 2, 2], pretrained=True, progress=True,<br>
num_classes=NUM_CLASS)</p>
<pre><code>def forward(self, x):
    logit_age = self.resnet(x)
    return logit_age
</code></pre>
<p>def train_net(pretrain=False):<br>
logging.basicConfig(level=logging.INFO,<br>
format=’%(asctime)s - %(name)s-%(levelname)s-%(message)s’,<br>
filename=‘display.log’)<br>
logger = logging.getLogger(<strong>name</strong>)</p>
<pre><code>model = AgeClassifier()
if pretrain:
    model_path = getModel(AGE_MODEL_OUTPUT)
    model.load_state_dict(torch.load(model_path))
    print('load model:{}'.format(model_path.split('/')[-1]))
model.to(DEVICE)
train_loader, test_loader = dataPre(mode='train')

optimizer = opt.Adam(model.parameters(), AGE_LR, betas=(0.5, 0.999))

###################
#    Age_Loss     #
###################
age_cls_criterion = nn.CrossEntropyLoss()

train_acc, num_class_age = 0, 0
for epoch in range(AGE_EPOCH):
    model.train()
    for batch_idx, data in enumerate(train_loader):
        feature, age_label = data
        feature = feature.to(DEVICE)
        age_label = age_label.to(DEVICE)

        optimizer.zero_grad()

        age_pre = model(feature)
        loss = age_cls_criterion(age_pre, age_label)

        loss.to(DEVICE)
        loss.backward()

        optimizer.step()
        out_age = torch.max(age_pre, 1)[1]

        train_acc += (out_age == age_label).sum()
        num_class_age += age_label.size(0)
</code></pre>
<p>…</p>

ptrblck: <aside class="quote no-group" data-username="Weng_zhiqiang" data-post="1" data-topic="64102">
<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/weng_zhiqiang/48/18542_2.png" class="avatar"> Weng_zhiqiang:</div>
<blockquote>
<p>Yeah, the training acc is 98%, but it still 50%</p>
</blockquote>
</aside>
<p>I assume you are referring to the training and validation accuracy, respectively?<br>
If so, it seems your model is indeed overfitting.<br>
You could try to increase the regularization, more aggressive data augmentation, make sure both data splits contain images from the same domain and the same preprocessing.</p>

Weng_zhiqiang: <p>Hi Ptrblck,<br>
Yes, these refer to training and validation accuracy. I’m sure the data comes from the same domain and the same preprocessing. Actually, I have tried to do some data augmentation, and maybe it works not as my expect. Indeed, after the data augmentation, the validation accurancy arised. However, it rise at 60% and stop at that point.</p>