Pytorch CNN - no improvement in accuracy

Niraja: <p>I am working on Age n Gender prediction using the UTKFace dataset.<br>
My dataset has 10497 images. From that 8397 were used for training and 2100 were used for testing datasets.<br>
In my model problem is that age accuracy is constant but gender accuracy is either constant or it is decreasing.</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://colab.research.google.com/drive/1gbL5P3uYvYm08bJ3FBJuJPuPC6vU_3hR?usp=sharing">
  <header class="source">
      <img src="https://ssl.gstatic.com/colaboratory-static/common/988a0649b1f000fb05eb8e47caf2b8c7/img/favicon.ico" class="site-icon" width="128" height="128">

      <a href="https://colab.research.google.com/drive/1gbL5P3uYvYm08bJ3FBJuJPuPC6vU_3hR?usp=sharing" target="_blank" rel="noopener nofollow ugc">colab.research.google.com</a>
  </header>

  <article class="onebox-body">
    <img src="https://colab.research.google.com/img/colab_favicon_256px.png" class="thumbnail onebox-avatar" width="260" height="260">

<h3><a href="https://colab.research.google.com/drive/1gbL5P3uYvYm08bJ3FBJuJPuPC6vU_3hR?usp=sharing" target="_blank" rel="noopener nofollow ugc">Google Colaboratory</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<p>
This is the link of my model program.<br>
I have print predicted and correct labels in test models. I tried to solve this problem but it could not. Thank you in advance.</p>

J_Johnson: <p>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.</p>
<p>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”.</p>
<p>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).</p>

Niraja: <p>Yes. I add more convolutional layers and change the linear output for gender to 1  and using BCELoss or BCEWithLogitsLoss</p>

Niraja: <p>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.</p>

J_Johnson: <p>You’d probably do well to consider or review ResNet and other successful classification models for ideas.</p>
<p>Skip connections are also a good consideration, if you have over 8 layers from input to model output.</p>

Niraja: <p>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.”<br>
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.</p>

J_Johnson: <p>Please see here:</p>
<p><a href="https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html</a></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/2/3218745454a5fe54dcf27bdba538ce876a5182df.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/3218745454a5fe54dcf27bdba538ce876a5182df" title="IMG_20230204_123237"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/2/3218745454a5fe54dcf27bdba538ce876a5182df_2_690x375.jpeg" alt="IMG_20230204_123237" data-base62-sha1="79agxNKpISc5WzNbNOy8rxl2hvV" width="690" height="375" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/2/3218745454a5fe54dcf27bdba538ce876a5182df_2_690x375.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/3/2/3218745454a5fe54dcf27bdba538ce876a5182df_2_1035x562.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/2/3218745454a5fe54dcf27bdba538ce876a5182df.jpeg 2x" data-dominant-color="F7F5F5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">IMG_20230204_123237</span><span class="informations">1080×588 73.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<pre><code class="lang-auto">x=torch.rand((50,1))
print(x.size())

x=x.view(-1)
print(x.size())
</code></pre>