How to handle overfitting properly

NextDoorToHell: <p>I am training a CNN regression model with a 34560 size dataset. I have already got a training error rate less than 5%, but the validation error rate is over 60%. It seems to be an overfitting problem. And I tried the four ways to solve the problem, but none of them works well:</p>
<ol>
<li>Increase the dataset size</li>
<li>Reduce the model complexity</li>
<li>Add a dropout layer before the output layer</li>
<li>Use L2 regularization / weight decay<br>
Probably I did not use them in the right way. Can someone tell some details of these methods? Or are there any other ways to solve the overfitting problem?</li>
</ol>

J_Johnson: <p>If you always send the training data into the model the same way, you’ll likely have overfitting.</p>
<p>Augmentations are a way to “extend” your dataset and build a more robust model. This is basically done by altering the images on the fly with crops, filters, flips, rotations, etc.</p>
<p>See here:<br>
<a href="https://pytorch.org/vision/main/transforms.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/vision/main/transforms.html</a></p>
<p>And here:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/albumentations-team/albumentations">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/albumentations-team/albumentations" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:480/235;"><img src="https://repository-images.githubusercontent.com/136265021/094cf680-b83f-11e9-9512-e4b538ed8e4d" class="thumbnail" width="480" height="235"></div>

<h3><a href="https://github.com/albumentations-team/albumentations" target="_blank" rel="noopener nofollow ugc">GitHub - albumentations-team/albumentations: Fast image augmentation library...</a></h3>

  <p>Fast image augmentation library and an easy-to-use wrapper around other libraries. Documentation:  https://albumentations.ai/docs/ Paper about the library: https://www.mdpi.com/2078-2489/11/2/125 -...</p>


  </article>

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

  <div style="clear: both"></div>
</aside>


NextDoorToHell: <p>Yes, data augmentations work well for classification. But my task is a regression one, and I never tried augmentations on regression. Could you explain more about data augmentation on regression tasks?</p>

J_Johnson: <p>The appropriate augmentations to use will be determined by the target of the regression model. For example, if your target was to find the distance measured between two points, rotation, hue, brightness, etc. would be appropriate to augment. But you probably shouldn’t crop or sheer.</p>
<p>The question ought to be, will this type of augmentation materially change the target? Nevertheless, it’s still a good idea to incorporate appropriate forms of augmentation. It prevents your model from memorizing irrelevant features in the data.</p>

NextDoorToHell: <p>My task is to simulate an optical grating. The inputs are 8 coefficients and a 128x128 binary image, and the outputs are 80 numbers.<br>
First, I extend the 8 coefficients into a 128x128 matrix. Then I apply CNN and average pooling twice on both the matrix and the binary image, and concatenate both to get 64x32x32 tensor. After 5 times CNN and average pooling on the tensor, I flatten the tensor and apply a FC layer to get 80 outputs. This is basically what my model is like.<br>
So what kinds of data augmentation do you recommend for my model?</p>

J_Johnson: <p>Ask yourself this:</p>
<ol>
<li>If I performed ______ augmentation on the image, would I still be able to determine what the 80 outputs(targets) should be(with sufficient training)?</li>
<li>And would the targets still be the same?</li>
</ol>
<p>Take rotation, for example. Would rotating the image n degrees alter what the targets should be? If not, then this would be a good target augmentation. Rotations alone can multiply your dataset size by 360.</p>
<p>Then go through each augmentation and determine if it would satisfy those conditions.</p>