Pytorch CNN - no improvement in accuracy

I am working on Age n Gender prediction using the UTKFace dataset.
My dataset has 10497 images. From that 8397 were used for training and 2100 were used for testing datasets.
In my model problem is that age accuracy is constant but gender accuracy is either constant or it is decreasing.

This is the link of my model program.
I have print predicted and correct labels in test models. I tried to solve this problem but it could not. Thank you in advance.

Age is easy to determine by looking at the smoothness of skin over the entire face and the number of defects, i.e. texture, which a simple kernel can handle just fine. However, gender features are more macro-oriented.

I noticed you’re using a limited number of convolutions and that the outsize from your convolutions is 8x8 pixels. Perhaps a few more convolutions would be in order to distill that down to a size of 1. Doing so will likely give your model a better macro representation of the image when it enters into the linear layers for “decision time”.

On a side note, you might also consider setting the final linear output for gender to 1 and using BCELoss or BCEWithLogitsLoss(this won’t need a final Sigmoid activation and is faster).

Yes. I add more convolutional layers and change the linear output for gender to 1 and using BCELoss or BCEWithLogitsLoss

1 Like

I will make the changes as per you suggested. Another question is, is my convolutional model, training model and validation model correct? Thank you in advance.

You’d probably do well to consider or review ResNet and other successful classification models for ideas.

Skip connections are also a good consideration, if you have over 8 layers from input to model output.

1 Like

I done the changes as per your advice but when I conducted out_features for gender = 1, with BCELoss(), that time it gives the error “ValueError: Using a target size (torch. Size([50])) that is different to the input size (torch. Size([50, 1])) is deprecated. Please verify that they are of the same size.”
My batch size is set at 50. How to fix this error? I attempted to address the problem but was unable. Thank you in advance.

Please see here:

https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html

x=torch.rand((50,1))
print(x.size())

x=x.view(-1)
print(x.size())