# Yolov5 with Pytorch Overfitting Problem

**URL:** <https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588>\
**Category:** Uncategorized\
**Created:** [July 2, 2021, 1:12am UTC](https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588 "2021-07-02T01:12:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasar\_Niyazoglu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/yasar_niyazoglu/32/35933_2.png) [@Yasar\_Niyazoglu](https://discuss.pytorch.org/u/Yasar_Niyazoglu)\
**Post date:** [July 2, 2021, 1:12am UTC](https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588/1 "2021-07-02T01:12:00Z")

</div>

Hello there. I trained in yolov5 with my own data set and my map values ​​are like this. As a result of the model I made with 30 epochs, it did a normal quality job when testing with video, but when I tested the same video with the model formed as a result of 300 epochs, it did a worse job than 30 epochs. how can i solve this.

 ![Ekran Alıntısı2](https://discuss.pytorch.org/uploads/default/original/3X/9/3/933d36274432d44498c2e1a596be85ee37b7817e.png)  
 ![Ekran Alıntısı1](https://discuss.pytorch.org/uploads/default/original/3X/9/f/9fe9c5c971afcee69a0f462041c796d9e88466d7.png)  
 ![Ekran Alıntısı](https://discuss.pytorch.org/uploads/default/original/3X/a/5/a56dd35d018bdedf65067b80524ea478e5cc46ef.png)

---

<div class="post-metadata">

**Author:** ![SarthakJain](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@SarthakJain](https://discuss.pytorch.org/u/SarthakJain)\
**Post date:** [July 2, 2021, 5:04am UTC](https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588/2 "2021-07-02T05:04:35Z")

</div>

Hi,

As you have correctly identified in the title, the model suffers from overfitting.  
Especially for object detection these are some specific ways you can solve them:

**Use Data Augmentation using the Albumentations Library**  
Data Augmentations is a way to prevent your model from learning on noise by simply altering the data to express more variety. This can introduce helpful aspects of your model like translational or rotational invariance. You can apply these augmentations to the frames of your video and a great thing is that these albumentations work to transform both boxes and images so you don’t have to worry about that.  
I suggest you check out this github and doc to get started:

- [Albumentations Documentation](https://albumentations.ai/docs/)
- [GitHub - albumentations-team/albumentations: 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](https://github.com/albumentations-team/albumentations)

Additionally you can try to obtain more data by looking for other well known dataset like openImages, Imagenet, COCO etc. and altering your dataclass to work on images that share the same classes you are already testing for.

Another thing to try is to increase the weight decay in your model. Note: You can also find more geeneral advice on overfitting on the internet but these are some specific ways you can tackle the issue you have right now.

Sarthak

---

<div class="post-metadata">

**Author:** ![Yasar\_Niyazoglu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/yasar_niyazoglu/32/35933_2.png) [@Yasar\_Niyazoglu](https://discuss.pytorch.org/u/Yasar_Niyazoglu)\
**Post date:** [July 2, 2021, 1:41pm UTC](https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588/3 "2021-07-02T13:41:45Z")

</div>

Thank you for your interest.  
I will try to increase data. You said weight reduction in the model, what exactly is this? you mean my L2 norm

---

<div class="post-metadata">

**Author:** ![SarthakJain](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@SarthakJain](https://discuss.pytorch.org/u/SarthakJain)\
**Post date:** [July 4, 2021, 2:44am UTC](https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588/4 "2021-07-04T02:44:04Z")

</div>

It depends on your optimizer.  
Use this documentation to find out more on whether it L1, L2 or some smart combination.  
[https://pytorch.org/docs/stable/optim.html](https://pytorch.org/docs/stable/optim.html)

Check this image as an example.

 ![Screen Shot 2021-07-03 at 7.41.12 PM](https://discuss.pytorch.org/uploads/default/original/3X/8/7/874467dbc728f6572172b3fcff2d12445a3007b5.png)

Also, in addtion to more data, I really suggest you check out the albumentations library as that can add a lot to your model.

Sarthak Jain

---

<div class="post-metadata">

**Author:** ![Yasar\_Niyazoglu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/yasar_niyazoglu/32/35933_2.png) [@Yasar\_Niyazoglu](https://discuss.pytorch.org/u/Yasar_Niyazoglu)\
**Post date:** [July 5, 2021, 2:04pm UTC](https://discuss.pytorch.org/t/yolov5-with-pytorch-overfitting-problem/125588/5 "2021-07-05T14:04:32Z")

</div>

thank you my friend. i will do what you say
