WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.18k stars 4.17k forks source link

How to do gradient accumulation or how to check yolov7 is doing gradient accumulation #1663

Open bhuvneshsaini opened 1 year ago

bhuvneshsaini commented 1 year ago

I have 4GB memory GPU which can support at most batch size of 8 images but I want to train at least 16 images batch and some where on internet I heard the concept gradient accumulation biut don't know how this thing can work in yolov7.

eliavaxon commented 1 year ago

You have a hyper-parameter named "nbs" that does exactly what you need. It is hard coded here:

https://github.com/WongKinYiu/yolov7/blob/3b41c2cc709628a8c1966931e696b14c11d6db0c/train.py#L110

ryankert01 commented 3 months ago

Does that mean I always use a batch_size of 64, while I use CLI like this?

python yolov7/train.py --device 0 --batch-size 1 --epochs 50 --data yolov7/data/AICUP.yaml --img 1280 1280 --cfg yolov7/cfg/training/yolov7-AICUP.yaml --weights 'pretrained/yolov7-e6e.pt' --name yolov7-AICUP --hyp yolov7/data/hyp.scratch.custom.yaml