Yolov5: How to change default parameters via --hyp?

Created on 13 Jul 2020  ·  5Comments  ·  Source: ultralytics/yolov5

❔Question

Dear all,
sadly the documentation is a little bit..small on some ends ;).

I know that I can change the hyperparameters via --hyp HYP, but which format is exptected for HYP?

$ python train.py --img 640 --batch 16 --epochs 5 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --weights '' **--hyp HYP**

I would like to change to ADAM and increase the fl_gamma hyper-parameter.

Additional context

Some older tutorials (like https://mc.ai/yolo-v5%E2%80%8A-%E2%80%8Aexplained-and-demystified-2/) just provide wrong infos... --adam is definitely not helping ;).

Thanks a lot!

question

Most helpful comment

Hi,

Here is an example of a working hyp.yaml file (note that anything after # is a comment, and can be removed):

optimizer: 'adam'
lr0: 0.001  # initial learning rate (SGD=1E-2, Adam=1E-3)
momentum: 0.95  # momentum
weight_decay: 0.0  # optimizer weight decay
giou: 0.05  # giou loss gain
cls: 0.58  # cls loss gain
cls_pw: 1.0  # cls BCELoss positive_weight
obj: 1.0  # obj loss gain (*=img_size/320 if img_size != 320)
obj_pw: 1.0  # obj BCELoss positive_weight
iou_t: 0.20  # iou training threshold
anchor_t: 4.0  # anchor-multiple threshold
fl_gamma: 0.0  # focal loss gamma (efficientDet default is gamma=1.5)
hsv_h: 0.014  # image HSV-Hue augmentation (fraction)
hsv_s: 0.68  # image HSV-Saturation augmentation (fraction)
hsv_v: 0.36  # image HSV-Value augmentation (fraction)
degrees: 0.0  # image rotation (+/- deg)
translate: 0.0  # image translation (+/- fraction)
scale: 0.5  # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)

@glenn-jocher , maybe adding that example hyp.yaml for optimal COCO values would help users see the formatting for their own custom sets. It's also the same format of the output hyp.yaml file, but in the case that a user doesn't check the runs folders...

All 5 comments

Hello @Betm4n, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

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 model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

For more information please visit https://www.ultralytics.com.

Of course i checked all tutorials before asking...

Hi,

Here is an example of a working hyp.yaml file (note that anything after # is a comment, and can be removed):

optimizer: 'adam'
lr0: 0.001  # initial learning rate (SGD=1E-2, Adam=1E-3)
momentum: 0.95  # momentum
weight_decay: 0.0  # optimizer weight decay
giou: 0.05  # giou loss gain
cls: 0.58  # cls loss gain
cls_pw: 1.0  # cls BCELoss positive_weight
obj: 1.0  # obj loss gain (*=img_size/320 if img_size != 320)
obj_pw: 1.0  # obj BCELoss positive_weight
iou_t: 0.20  # iou training threshold
anchor_t: 4.0  # anchor-multiple threshold
fl_gamma: 0.0  # focal loss gamma (efficientDet default is gamma=1.5)
hsv_h: 0.014  # image HSV-Hue augmentation (fraction)
hsv_s: 0.68  # image HSV-Saturation augmentation (fraction)
hsv_v: 0.36  # image HSV-Value augmentation (fraction)
degrees: 0.0  # image rotation (+/- deg)
translate: 0.0  # image translation (+/- fraction)
scale: 0.5  # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)

@glenn-jocher , maybe adding that example hyp.yaml for optimal COCO values would help users see the formatting for their own custom sets. It's also the same format of the output hyp.yaml file, but in the case that a user doesn't check the runs folders...

This is it, thanks a lot. If I might make a suggestion: Please make it easy configurable ( --adam) and please provide reasonable default values for both, SGD AND Adam. ;) Thanks a lot guys!

Hi,

Here is an example of a working hyp.yaml file (note that anything after # is a comment, and can be removed):

optimizer: 'adam'
lr0: 0.001  # initial learning rate (SGD=1E-2, Adam=1E-3)
momentum: 0.95  # momentum
weight_decay: 0.0  # optimizer weight decay
giou: 0.05  # giou loss gain
cls: 0.58  # cls loss gain
cls_pw: 1.0  # cls BCELoss positive_weight
obj: 1.0  # obj loss gain (*=img_size/320 if img_size != 320)
obj_pw: 1.0  # obj BCELoss positive_weight
iou_t: 0.20  # iou training threshold
anchor_t: 4.0  # anchor-multiple threshold
fl_gamma: 0.0  # focal loss gamma (efficientDet default is gamma=1.5)
hsv_h: 0.014  # image HSV-Hue augmentation (fraction)
hsv_s: 0.68  # image HSV-Saturation augmentation (fraction)
hsv_v: 0.36  # image HSV-Value augmentation (fraction)
degrees: 0.0  # image rotation (+/- deg)
translate: 0.0  # image translation (+/- fraction)
scale: 0.5  # image scale (+/- gain)
shear: 0.0 # image shear (+/- deg)

@glenn-jocher , maybe adding that example hyp.yaml for optimal COCO values would help users see the formatting for their own custom sets. It's also the same format of the output hyp.yaml file, but in the case that a user doesn't check the runs folders...

Hi, @alexstoken could you please tell me waht are cls loss gain & cls BCELoss positive_weight, for me, it is too abstract, or could you please provide some reference materials, It would be greatly appreciated !

Was this page helpful?
0 / 5 - 0 ratings