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

Layer Wise Training #11081

Closed
1 task done
Enverrrr opened this issue Feb 28, 2023 · 9 comments
Closed
1 task done

Layer Wise Training #11081

Enverrrr opened this issue Feb 28, 2023 · 9 comments
Labels
question Further information is requested

Comments

@Enverrrr
Copy link

Search before asking

Question

Hello,
I need to train network by split it 'cause I have little free memory. I've tried how to solve it however I couldn't find any solutions.

Are there any documents I missed out?

Additional

No response

@Enverrrr Enverrrr added the question Further information is requested label Feb 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2023

👋 Hello @Enverrrr, 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

@Enverrrr
Copy link
Author

Enverrrr commented Feb 28, 2023

wave Hello @Enverrrr, thank you for your interest in YOLOv5 rocket! Please visit our star 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 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training question 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):

* **Notebooks** with free GPU: [![Run on Gradient](https://camo.githubusercontent.com/c9931a1689c37ab786edd3e1e5f59b9a6f7d097628c4689ce2432563ef884524/68747470733a2f2f6173736574732e706170657273706163652e696f2f696d672f6772616469656e742d62616467652e737667)](https://bit.ly/yolov5-paperspace-notebook) [![Open In Colab](https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667)](https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb) [![Open In Kaggle](https://camo.githubusercontent.com/a08ca511178e691ace596a95d334f73cf4ce06e83a5c4a5169b8bb68cac27bef/68747470733a2f2f6b6167676c652e636f6d2f7374617469632f696d616765732f6f70656e2d696e2d6b6167676c652e737667)](https://www.kaggle.com/models/ultralytics/yolov5)

* **Google Cloud** Deep Learning VM. See [GCP Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/google_cloud_quickstart_tutorial/)

* **Amazon** Deep Learning AMI. See [AWS Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/aws_quickstart_tutorial/)

* **Docker Image**. See [Docker Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/docker_image_quickstart_tutorial/) [![Docker Pulls](https://camo.githubusercontent.com/280faedaf431e4c0c24fdb30ec00a66d627404e5c4c498210d3f014dd58c2c7e/68747470733a2f2f696d672e736869656c64732e696f2f646f636b65722f70756c6c732f756c7472616c79746963732f796f6c6f76353f6c6f676f3d646f636b6572)](https://hub.docker.com/r/ultralytics/yolov5)

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 rocket

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

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

I'm sorry I couldn't find solutions

@Enverrrr
Copy link
Author

@glenn-jocher could you help me please

@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 28, 2023

👋 Hello! Thanks for asking about CUDA memory issues. YOLOv5 🚀 can be trained on CPU, single-GPU, or multi-GPU. When training on GPU it is important to keep your batch-size small enough that you do not use all of your GPU memory, otherwise you will see a CUDA Out Of Memory (OOM) Error and your training will crash. You can observe your CUDA memory utilization using either the nvidia-smi command or by viewing your console output:

Screenshot 2021-05-28 at 12 19 51

CUDA Out of Memory Solutions

If you encounter a CUDA OOM error, the steps you can take to reduce your memory usage are:

  • Reduce --batch-size
  • Reduce --img-size
  • Reduce model size, i.e. from YOLOv5x -> YOLOv5l -> YOLOv5m -> YOLOv5s > YOLOv5n
  • Train with multi-GPU at the same --batch-size
  • Upgrade your hardware to a larger GPU
  • Train on free GPU backends with up to 16GB of CUDA memory: Open In Colab Open In Kaggle

AutoBatch

You can use YOLOv5 AutoBatch (NEW) to find the best batch size for your training by passing --batch-size -1. AutoBatch will solve for a 90% CUDA memory-utilization batch-size given your training settings. AutoBatch is experimental, and only works for Single-GPU training. It may not work on all systems, and is not recommended for production use.

Screenshot 2021-11-06 at 12 31 10

Good luck 🍀 and let us know if you have any other questions!

@Enverrrr
Copy link
Author

Thanks for your advice.
Can I split the network or can I freeze different part of the network. For example train 50 epochs with backbone then 50 epochs head etc.

@glenn-jocher
Copy link
Member

@Enverrrr that's an unorthodox approach but yes you can use the --freeze command to freeze the first x layers, i.e. python train.py --freeze 10

@Enverrrr
Copy link
Author

Enverrrr commented Mar 1, 2023

@Enverrrr that's an unorthodox approach but yes you can use the --freeze command to freeze the first x layers, i.e. python train.py --freeze 10

I couldn't explain myself I think, I just want to get 1 single weight after training. I mean first of all I need to train backbone and then train other parts of the network with the helps of --freeze command in single run.

@Enverrrr
Copy link
Author

Enverrrr commented Mar 2, 2023

@glenn-jocher Hey I've question for you I don't use freeze method and train all the networks gpu memory is 3142MB according to nvidia-smi. When I am freezing 18 layers from 6 to 24 and gpu memory is 3118MB according to nvidia-smi. Could it be smaller than first situation. I mean yes it is smaller but wouldn't the difference be more?

@glenn-jocher
Copy link
Member

@Enverrrr Yes, freezing layers can indeed result in a smaller memory footprint, but the extent of the reduction depends on various factors such as the size of the frozen layers and the specific operations performed within those layers. It's not uncommon for the reduction to be less than expected. Additionally, other factors such as the size of the model, batch size, and input image size can also influence GPU memory utilization. If your goal is to minimize memory usage, you may need to further experiment with different combinations of frozen layers and training settings to achieve the desired outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants