Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection between learning rate and total number of training epochs #11475

Closed
1 task done
eypros opened this issue May 3, 2023 · 7 comments
Closed
1 task done

Connection between learning rate and total number of training epochs #11475

eypros opened this issue May 3, 2023 · 7 comments
Labels
question Further information is requested Stale

Comments

@eypros
Copy link

eypros commented May 3, 2023

Search before asking

Question

I was training a Yolov5n model on Coco dataset using the default parameters with the exception of batch size 64 (I could not afford higher in my machine). Anyway, after the training ended I got a mAP50 of 45.09% which I found acceptable though it was obviously less than 45.7% (aka the reported precision). I figured out that the smaller batch size might impact the performance (as mentioned in the issues).

Then, I tried to train for more epochs without changing anything to the model's parameters. At first the mAP50 for both experiments coincided in large degree (to my satisfaction) but after some point there was a small at first and then large diversion between the precisions.

first epochs:
image

next epochs:
image
In the previous plots the blue is the initial run and with the black line is the second attempt.

My question, seeing the aforementioned behavior, is whether the actual learning rate is affected by the total number of epochs. As I investigated the code I think I didn't found any connection, meaning that the learning rate would be the same up to epoch 300 (the final epoch of the first run). If this is the case, is it normal to observe such diversions in mAP between different runs?

Additional

No response

@eypros eypros added the question Further information is requested label May 3, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2023

👋 Hello @eypros, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@eypros hi!

Great question! From analyzing the graphs, it seems like the model's performance has plateaued around epochs 250-300, and continuing to train the model past that point hasn't been helpful in improving performance.

As for your question about learning rate, the learning rate schedule actually decays the learning rate over time as the model gets closer to convergence. Here's an example of a learning rate schedule from the train.py script:

optimizer = torch.optim.SGD(model.parameters(), lr=hyp['lr0'], momentum=hyp['momentum'], nesterov=True)
lf = lambda x: ((1 + math.cos(x * math.pi / hyp['epochs'])) / 2) * (1 - hyp['lrf']) + hyp['lrf']  # cosine
scheduler = lr_scheduler.LambdaLR(optimizer, lr_lambda=lf)

The lr_lambda function used by the PyTorch learning rate scheduler decays the learning rate as the model gets closer to convergence. In this case, the learning rate takes on a cosine function whose minimum is hyp['lrf'] and whose maximum is hyp['lr0'].

To answer your question, if train.py has been used to train the model and the lf schedule is used, then the learning rate will already be decaying over time, which means that the number of epochs shouldn't cause sudden dives in mAP.

Hope that helps!

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

3 similar comments
@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added Stale and removed Stale labels Jun 3, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jul 5, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants