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

Train YOLOV5 in 2 or 3 times, because of insufficient memory to train the all dataset in one time #8477

Closed
1 task done
EdouardEPFL opened this issue Jul 5, 2022 · 6 comments
Labels
question Further information is requested

Comments

@EdouardEPFL
Copy link

EdouardEPFL commented Jul 5, 2022

Search before asking

Question

I'm currently trying to train on a custom dataset that has around 25k images.

Despite a good computer configuration: 32,0 GO of memory,
AMD Ryzen 7 3800X 8-Core
NVIDIA Quadro RTX4000

I'm facing the problem of the
error: (-4:Insufficient memory) Failed to allocate xxxx bytes in function 'cv::OutOfMemoryError'

Hence, as I don't want to downscale my images or reduce my dataset or disable the --cache options, I wanted to know if I can train my model in 2 or 3 times to avoid the problem.

I'm also wondering (if it's not possible to train in few times), if I should use transfer learning to learn in 2 or 3 times as I'm training with weights from scratch.

Thank you in advance for any kind of help.

Additional

No response

@EdouardEPFL EdouardEPFL added the question Further information is requested label Jul 5, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2022

👋 Hello @EdouardEPFL, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

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

CI CPU testing

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

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 5, 2022

@EdouardEPFL 👋 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!

@EdouardEPFL
Copy link
Author

Hello, thank you for the answer but I wasn't talking about gpu memory. I was talking about RAM-Memory because of --cache. However thank you for those explanations about the gpu memory

@glenn-jocher
Copy link
Member

@EdouardEPFL oh, well if RAM caching is using up all your memory then you can try disk caching:

python train.py --cache disk

@EdouardEPFL
Copy link
Author

Thank you very much, tha'ts what I was looking for !

@glenn-jocher
Copy link
Member

@EdouardEPFL you're welcome! If you have any more questions or need further assistance, feel free to ask. Good luck with your training!

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