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

why training custom data use CPU instead of GPU #7173

Closed
1 task done
amieruddin opened this issue Mar 28, 2022 · 17 comments
Closed
1 task done

why training custom data use CPU instead of GPU #7173

amieruddin opened this issue Mar 28, 2022 · 17 comments
Labels
question Further information is requested Stale

Comments

@amieruddin
Copy link

Search before asking

Question

Hi,
i have 20k of images and already do data preparation(follow guideline by ultalytics).

I don't make any changes on any yolov5 file/hyp. I just use default setting by yolov5.

When training was started, i noticed that the training use all CPU memory (86%) rather then GPU (6%).

My device spec as below :
OS : Windows 10
GPU : NVIDIA RTX 3090
CPU : i9

Command for training : python train.py --img 640 --batch 16 --epochs 1500 --data dataset.yaml --weights yolov5s.pt --device 0

My question is why my device trained the yolo model using CPU instead of GPU? is that any line i need to make changes?
Need help to train the yolo on gpu..Thank you.

CPU_GPU Training

training epoch

Additional

No response

@amieruddin amieruddin added the question Further information is requested label Mar 28, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 28, 2022

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

@niiita
Copy link

niiita commented Mar 28, 2022

Hi, I have the same question!^^
How can I train on GPU instead of CPU?

@CCRcmcpe
Copy link
Contributor

You should use the cuda version of torch.
image

Uninstall your current version, and follow https://pytorch.org/get-started/locally/

@CCRcmcpe
Copy link
Contributor

@amieruddin I mean torch version. It's not related to the CUDA installed on your system.

@amieruddin
Copy link
Author

im using both CUDA toolkit v.11.3 and Pytorch v.11.3..

based on my installation before...if i install Pytorch not same version with cuda toolkit...it will get error message when training

@amieruddin
Copy link
Author

based on your link to https://pytorch.org/get-started/locally/ , it show latest version of PyTorch is 11.3.

@CCRcmcpe , is current PyTorch version 11.3 not support GPU to training YOLOv5?

@CCRcmcpe
Copy link
Contributor

CCRcmcpe commented Mar 28, 2022

@amieruddin You have a huge misunderstanding. Latest pytorch version is 1.11.0, which uses CUDA 11.3. There's no pytorch 11.3. And you should choose compute platform CUDA and install.

@amieruddin
Copy link
Author

@CCRcmcpe , I choose Pytorch Build : LTS 1.8.2 and install using the command :

pip3 install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html

but it show error like this.

error install

then when i check pip freeze : it show only torch downgrade to torch==1.8.2+cu111.
torchaudio and torchvision unsuccessful to install torchvision==0.9.2+cu111 torchaudio===0.8.2

torch vision

@CCRcmcpe

This comment was marked as outdated.

@CCRcmcpe

This comment was marked as outdated.

@CCRcmcpe
Copy link
Contributor

CCRcmcpe commented Mar 28, 2022

@amieruddin Alright. Seems you are already using GPU to train. My fault. The reason your GPU usage is so low is because your small batch size does not match your GPU performance. Increase your batch size to 32 or higher to solve the problem.

@amieruddin
Copy link
Author

Thank you @CCRcmcpe, actually there is nothing wrong with my training result/model...because after training, I run the model and it work fine.

I just need help to train the model using GPU instead of CPU. Currently I set the epoch to 1500, and it takes me 5 days to finish the training. I want to speed up the time taken.

I try your suggestion to increase the batch size. I try batch size 32 & 64, it still use CPU, not GPU.
the command : python train.py --img 640 --batch 64 --epochs 1500 --data dataset.yaml --weights yolov5s.pt --device 0

After run this command, task manager show it use 100% of the CPU.
Also i got the error 'out of memory' at terminal

error100%_0
error100%_1

@glenn-jocher
Copy link
Member

glenn-jocher commented Mar 30, 2022

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

@github-actions
Copy link
Contributor

github-actions bot commented Apr 30, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

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 YOLOv5 🚀 and Vision AI ⭐!

@ENNURSILA
Copy link

ENNURSILA commented Nov 15, 2022

@amieruddin
Were you able to fix the problem ?

@Smokedhammer
Copy link

@amieruddin Were you able to fix the problem ?

pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

Do this above step. and then try running the train command directly from the command line, this made it work somehow!

There should be a prompt on the command line which shows you using the GPU

@ENNURSILA
Copy link

@amieruddinSorunu çözebildiniz mi?

pip kurulumu torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

Yukarıdaki adımı yapın. ve ardından doğrudan komut satırından tren komutunu çalıştırmayı deneyin, bu bir şekilde çalışmasını sağladı!

Komut satırında, GPU'yu kullandığınızı gösteren bir bilgi istemi olmalıdır.

Thanks a lot

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

6 participants