ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.24k stars 16.44k forks source link

Training stops to converge after a while #6337

Closed Yu-Hang closed 2 years ago

Yu-Hang commented 2 years ago

Search before asking

Question

Hi there,

Any idea why this happens? Training seems to be working for the first 100 epochs or so as validation losses are dropping, but then things started to derail from there. How should I adjust?

results

Additional

python train.py --img 1120 --batch 8 --epochs 300 --data '/slurm_storage/yuh5/data/thin_Pf_YOLOv5/5_fold_tiles_falciparum_vivax/exp1/data.yaml' --cfg ./models/custom_yolov5m.yaml --hyp ./data/hyp_evolved_medium.yaml --weights yolov5m.pt --name yolov5m_results --cache --rect

lr0: 0.00285 lrf: 0.396 momentum: 0.98 weight_decay: 0.00054 warmup_epochs: 3.09 warmup_momentum: 0.826 warmup_bias_lr: 0.0308 box: 0.0515 cls: 0.966 cls_pw: 0.908 obj: 0.2 obj_pw: 1.22 iou_t: 0.2 anchor_t: 3.9 anchors: 2.0 fl_gamma: 0.0 hsv_h: 0.0108 hsv_s: 0.288 hsv_v: 0.167 degrees: 0.114 translate: 0.0461 scale: 0.219 shear: 0.0218 perspective: 0.0 flipud: 0.315 fliplr: 0.6 mosaic: 0.427 mixup: 0.0

glenn-jocher commented 2 years ago

@Yu-Hang your model is overfitting your training set. See https://en.wikipedia.org/wiki/Overfitting

Yu-Hang commented 2 years ago

@glenn-jocher What would you suggest in this case considering the highest Precision and Recall were only around 0.6... Is the only way going forward to get better training data?

glenn-jocher commented 2 years ago

@Yu-Hang 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results.

Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.

If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name directory, typically yolov5/runs/train/exp.

We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.

Dataset

COCO Analysis

Model Selection

Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.

YOLOv5 Models

Training Settings

Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.

Further Reading

If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/

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

Yu-Hang commented 2 years ago

@glenn-jocher More info:

labels labels_correlogram confusion_matrix

Test batch: Label test_batch0_labels Pred test_batch0_pred